如何从Angular导入中删除.js后缀

时间:2017-06-07 13:23:24

标签: angular systemjs

我想从Angular导入中删除.js后缀。

不想要(现在可以使用): import { Example } from './whatever/example.js';

通缉: import { Example } from './whatever/example';

我怀疑我错过了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
      // other libraries

    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

1 个答案:

答案 0 :(得分:3)

尝试在包中添加:

'.': {
    defaultJSExtensions: 'js'
}

这样的包现在看起来像:

// packages tells the System loader how to load when no filename and/or no extension
packages: {
'.': {
    defaultJSExtensions: 'js'
},
app: {
    defaultExtension: 'js'
},
rxjs: {
    defaultExtension: 'js'
    }
}