Angular 2 Webpack AOT无法解析entryModule

时间:2017-02-13 20:16:38

标签: angular typescript webpack

我正在尝试使用Angular 2和Webpack设置AOT构建(JIT构建工作正常)。每当我尝试构建它时,我都会得到ERROR in Could not resolve "src/app/app.module" from "src/app/app.module"。我尝试删除AotPlugin之外的webpack插件,使用AotPlugin选项的相对/绝对路径的每个组合,都没有结果。我使用webpack 2.2.1,typescript 2.0.10,@ ngtools / webpack 1.2.9和节点版本6.9.4。任何帮助都会很棒,谢谢!

来自webpack.config的小部件:

module: {
  rules: [
    { test: /\ts$/, loader: @'ngtools/webpack }
  ]
}

plugins: [
  new webpack.NoEmitOnErrorsPlugin(),
  new AotPlugin({
    tsConfigPath: './tsconfig.json',
    entryModule: 'src/app/app.module#AppModule',
    mainPath: 'src/main'
    }),
  new webpack.optimize.UglifyJsPlugin({
    beautify: false,
    mangle: {
      screw_ie8: true,
      keep_fnames: true
    },
    compress: {
      warnings: false,
      screw_ie8: true
    },
    comments: false
  }),
  new ExtractTextPlugin('[name].[hash].css'),
  new webpack.DefinePlugin({
    'process.env': {
    'ENV': JSON.stringify(ENV)
    }
  })
]

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "src",
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  },
  "compileOnSave": false
}

1 个答案:

答案 0 :(得分:3)

回答我自己的问题,一定有路径问题。我一直在为路径使用辅助函数,出于某些原因,在这种情况下没有。

辅助功能:

var path = require('path');

var _root = path.resolve(__dirname, '..');
function root(args) {
  args = Array.prototype.slice.call(arguments, 0);
  return path.join.apply(path, [_root].concat(args));
}

使用:

entryModule: root('src', 'app', 'app.module#AppModule')