Typescript中的System.Import不会覆盖默认路径

时间:2016-09-18 14:05:43

标签: javascript angular typescript

我是Typescript和Angular2的新手。我有一个app文件夹,我正在创建ts文件,我正在尝试生成已编译的' js'文件到另一个文件夹构建。 '的js'文件正在成功生成,但是当我尝试使用import将文件System.import('built')设置为html时,脚本未被引用并抛出404。这两个应用程序都是应用程序。并且'建造'文件夹添加到根目录。 这是我的tsconfig.json:

{
  "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);

1 个答案:

答案 0 :(得分:1)

您需要将 app 的映射更改为内置,如图所示

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