我想实现角度的AOT教程: https://angular.io/docs/ts/latest/cookbook/aot-compiler.html角AOT和汇总 - 未捕获的ReferenceError:出口没有定义
使用NGC部分作品和它所产生AOT文件夹。然而,当我运行应用程序,我得到下面的错误
bundle.js:1 Uncaught ReferenceError: exports is not defined
我的代码如下: -
tsconfig-aot.json
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"files": [
"src/app/app.module.ts",
"src/main.ts"
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit" : true
},
"exclude": [
"node_modules",
"bower_components",
"typings/main",
"typings/main.d.ts"
]
}
执行后node_modules /的.bin/ngc -p tsconfig -aot.json,aot文件夹已成功生成。
main.ts
import { platformBrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from '../aot/src/app/app.module.ngfactory';
console.log('Running AOT compiled');
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
我的这么一读链接,“你需要编译这些TS文件作为ES2015模块,以受益于‘树摇晃’。这意味着必须成为一个只能指向main-aot.ts文件的配置文件(tsconfig-compile-aot.json)。“
tsconfig - 编译 - aot.json
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"files": [
"src/main.ts"
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit" : true
},
"exclude": [
"node_modules",
"bower_components",
"typings/main",
"typings/main.d.ts"
]
}
编译与TSC和tsconfig - 编译 - aot.json主aot.ts文件,再次为ES2015模块和生成您的js文件。在编译我得到我的js文件 我执行命令
tsc src/main.ts
汇总-config.js
import rollup from 'rollup'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify'
export default {
entry: 'src/main.js',
dest: 'bundle.js', // output a single application bundle
sourceMap: false,
format: 'iife',
onwarn: function(warning) {
// Skip certain warnings
// should intercept ... but doesn't in some rollup versions
if (warning.code === 'THIS_IS_UNDEFINED') { return; }
// console.warn everything else
console.warn(warning.message);
},
plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: 'node_modules/rxjs/**',
}),
uglify()
]
}
之后,我执行下面的命令 node_modules /的.bin /汇总-c rollup- config.js
然后执行npm run lite,我得到错误。
我没有看到tsconfig-aot.json'和'tsconfig - 编译 - aot.json'第一个已经'之间的区别有'es2015'模块类型 – yurzui
汇总配置应该有'main-aot'入口点用于生产 – yurzui
@yurzui:对不起,区别在于files部分,它只是一个名称问题。我的main.ts内容已经根据aot改变了,并且没有主要的ao – Shifs