我正在尝试实现AOT是一个很大的Angular 2应用程序。我使用tsc编译和webpack捆绑。在AOT之后应该减少捆绑尺寸,但是它会增加。我无法理解为什么。
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"lib": [
"es2015",
"dom"
],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noEmit": true,
"inlineSources": true,
"skipLibCheck": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"typings/main.d.ts",
"typings/main"
],
"filesGlob": [
"./src/**/*.ts",
"./test/**/*.ts",
"!./node_modules/**/*.ts",
"src/custom_typings.d.ts",
"typings/browser.d.ts"
],
"compileOnSave": false,
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false
},
"skipLibCheck": true,
"angularCompilerOptions": {
"genDir": "./compiled",
"entryModule": "src/app/app.module#AppModule"
},
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
}
}
webpack配置加载程序
{ test: /\.ts$/, loaders: ['awesome-typescript-loader', 'angular2-template-loader'], exclude: [/\.(spec|e2e|async)\.ts$/] },
main.aot.ts
import { enableProdMode} from '@angular/core';
import { platformBrowser } from '@angular/platform-browser';
if ('production' === process.env.ENV) {
enableProdMode();
}
import {AppModuleNgFactory} from '../compiled/src/app/app.module.ngfactory';
import {KeycloakService} from './app/keycloak/keycloak';
KeycloakService.init().then(
o => {
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
},
x => {
window.location.reload();
}
);