当使用ngc代替tsc时,或者使用@ ngtools / webpack中的AotPlugin时,应为每个角度模块生成ngfactory文件。 但在我的情况下,ngc静默地成功,但没有生成文件。
如果ngc没有打印任何消息,你可以给我一个如何调查的指导吗?
我尝试使用typescript@2.1.6和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
}
})
]
};
答案 0 :(得分:1)
使用typscript版本2.1.x
时,有很多未解决的问题现在使用Typescript 2.0.2。
来源:https://github.com/angular/angular/issues/11689
另一个原因可能是"gendir": "aot",
中应该有genDir
答案 1 :(得分:0)
我认为原因是@ ngtools / webpack不会生成这些文件。
@ ngtools / webpack处理内存中的这些文件并生成一个文件。