2016-09-18 43 views
0

我是Typescript和Angular2的新手。我有一个app文件夹,我在其中创建ts文件,并且正在尝试生成已编译的“js”文件到另一个构建的文件夹。 'Js'文件正在成功生成,但是当我尝试使用System.import('built')将文件import转换为html时,脚本未被引用并抛出404。 'app'和'built'文件夹都添加到根目录中。 这里是我的tsconfig.json:System.Import in Typescript不会覆盖默认路径

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false, 
    "outDir": "built" 
    } 
} 

我在这里导入脚本的index.html:

System.import('built').catch(function(err){ console.error(err); }); 

任何帮助。

编辑:在这里,我已经添加了systemjs.config.js:

(function (global) { 
    System.config({ 
    paths: { 
     // paths serve as alias 
     'npm:': 'node_modules/' 
    }, 
    // map tells the System loader where to look for things 
    map: { 
     // our app is within the app folder 
     app: 'app', 
     // angular bundles 
     '@angular/core': 'npm:@angular/core/bundles/core.umd.js', 
     '@angular/common': 'npm:@angular/common/bundles/common.umd.js', 
     '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', 
     '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', 
     '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', 
     '@angular/http': 'npm:@angular/http/bundles/http.umd.js', 
     '@angular/router': 'npm:@angular/router/bundles/router.umd.js', 
     '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', 
     // other libraries 
     'rxjs':      'npm:rxjs', 
     'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api', 
    }, 
    // packages tells the System loader how to load when no filename and/or no extension 
    packages: { 
     app: { 
     main: './main.js', 
     defaultExtension: 'js' 
     }, 
     rxjs: { 
     defaultExtension: 'js' 
     }, 
     'angular2-in-memory-web-api': { 
     main: './index.js', 
     defaultExtension: 'js' 
     } 
    } 
    }); 
})(this); 
+0

我只是测试它如果我做'System.import('built')。catch(function(err){console.error(err);});''你能告诉我你的'systemjs.config .js'? – micronyks

+0

@micronyks用systmjs.config.js更新了这个问题 – Vivek

回答

1

您需要如图所示改变应用内置的映射,

map: { 
     // our app is within the app folder 
     app: 'built',   //<-----changed 'app' to 'built'... 
     ... 
     ... 
} 
+0

明白了。我怎么错过了它。反正谢谢 – Vivek

+0

会发生!享受Angular2。 – micronyks