2017-02-15 79 views
1

当使用ngc代替tsc时,或者使用@ ngtools/webpack中的AotPlugin时,应该为每个角度模块生成ngfactory文件。 但在我的情况下,ngc默默成功,但没有生成文件。Angular2 AoT编译器没有ngfactory文件?

如果ngc不打印任何消息,你能否给我一个指导,甚至调查如何调查?

我试着用[email protected]和2.0.2 用@angular 2.3.1和2.4.7。 结果是一样的。

这里是我的tsconfig和webpack配置。在这两种情况下(运行webpack或运行ngc)它都不会创建文件。

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
    "target": "es5", 
    "module": "es2015", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": true, 
    "diagnostics": false, 
    "suppressImplicitAnyIndexErrors": true, 
    "outDir": "./compiled", 
    "rootDir": "./" 
    }, 
    "filesGlob": [ 
    "**/*.ts" 
    ], 
    "include": [ "typings" ], 
    "exclude": [ "node_modules" ], 
    "angularCompilerOptions": { 
    "entryModule": "app/module#AppModule", 
    "gendir": "aot", 
    "skipMetadataEmit": true, 
    "debug": true, 
    "trace": true, 
    "generateCodeForLibraries": true 
    } 
} 

和的WebPack文件:

/// <binding ProjectOpened='Watch - Development' /> 
var AotPlugin = require("@ngtools/webpack").AotPlugin; 

var path = require("path"); 
var webpack = require("webpack"); 
var basePath = path.join(__dirname, "wwwroot"); 

module.exports = { 
    context: basePath, 
    entry: { 
     main: ["./app/main.ts"], 
     productModule: "./app/components/product-module", 
     adminModule: "./app/components/admin-module" 
'rxjs/add/operator/map', 'rxjs/add/operator/delay'] 
     }, 
     output: { 
      path: path.join(__dirname, "wwwroot/built"), 
      filename: "[name].bundle.js", 
      sourceMapFilename: "[name].bundle.js", 
      publicPath: "built/" 
     }, 
     module: { 
      rules: [ 
       { 
        test: /\.html$/, 
        loader: "html-loader", 
        query: { 
         minimize: true, 
         ignoreCustomFragments: [/\{\{.*?}}/], 
         removeAttributeQuotes: false, 
         caseSensitive: true, 
         customAttrSurround: [ [/#/, /(?:)/], [/\*/, /(?:)/], [/\[?\(?/, /(?:)/] ], 
         customAttrAssign: [ /\)?\]?=/ ] , 
         root: basePath, 
         attrs: false // ['img:src', 'link:href'] 
        } 
       }, 
       { 
        test: /\.ts$/, 
        loaders: ["@ngtools/webpack"] 
       }//, 
       // { test: /\.css$/, loader: "style-loader!css-loader?root=." } 
      ] 
     }, 
     externals: { 
      "jquery": "jQuery" 
     }, 
     devtool: false, 
     plugins: [ 
      new AotPlugin({ 
       tsConfigPath: "./tsconfig.json", 
       entryModule: "app/module#AppModule" 
      }), 
      // new webpack.optimize.DedupePlugin(), 
      new webpack.optimize.CommonsChunkPlugin({ 
       //filename: "[name].c.bundle.js"//, 
       names: ["main"] 
      }) 
      //, 
      , new webpack.optimize.UglifyJsPlugin({ 
       sourceMap: true, 
       minimize: true, 
       acorn: true, 
       angular: true, 
       beautify: false, 
       compress: { 
        properties: true, 
        sequences: true, 
        dead_code: true, 
        drop_debugger: true, 
        unsafe_comps: true, 
        conditionals: true, 
        comparisons: true, 
        evaluate: true, 
        booleans: true, 
        keep_fargs: false, 
        loops: true, 
        unsafe: true, 
        angular: true, 
        unused: true, 
        cascade: true, 
        hoist_funs: true, 
        join_vars: true, 
        warnings: false 
       }, 
       output: { 
        comments: false 
       } 
      }) 
     ] 

    }; 

回答

1

有使用typscript版本2.1.x的

使用打字稿2.0.2现在,当很多关于这个悬而未决的问题。

来源:https://github.com/angular/angular/issues/11689

另一个原因可能是,有一个错字你"gendir": "aot",应该genDir

+1

非常感谢这个答案。我已经尝试过2.0.2,但由于我有时会遇到软件包使用的问题(我可以降级本地打字稿,但使用全球软件时可能会出现问题),我会再次检查。 genDir的东西,也是为此感谢。我无法捕捉到:) – doker

0

我想原因是@ ngtools /的WebPack不会产生这些文件。

@ngtools/webpack处理内存中的文件并生成一个文件。

相关问题