使用ngtools / webpack进行AOT编译,编译器仍然存在于bundle中

时间:2017-05-24 12:04:46

标签: javascript angular typescript webpack

我试图使用AOT编译来生成生产版本。一切似乎都运行得很好,除了我在供应商包中仍然有compiler。 AFAIK AOT编译的目标之一是从结果包中删除它并减少应用程序大小。

如何在结果包中生成没有compiler的正确AOT构建?

我的webpack配置:

var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');
var ngtools = require('@ngtools/webpack');
var AotPlugin = ngtools.AotPlugin;

const ENV = process.env.NODE_ENV = process.env.ENV = 'production';

module.exports = webpackMerge(commonConfig, {
    devtool: 'source-map',

    output: {
        path: helpers.root('../../../target/rhamt-web'),
        filename: 'js/[name].js',
        chunkFilename: 'js/[id].chunk.js'
    },

    module: {
        loaders: [
            {
                test: /\.ts$/,
                exclude: /jquery*\.js/,
                loaders: '@ngtools/webpack'
            }
        ]
    },

    plugins: [
        new webpack.NoEmitOnErrorsPlugin(),
        new ExtractTextPlugin('css/[name].css'),
        new AotPlugin({
            tsConfigPath: './tsconfig-production.json',
            basePath: '.',
            mainPath: 'src/main.ts',
            skipCodeGeneration: true
        }),
        new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618
            mangle: {
                keep_fnames: true
            }
        }),
        new webpack.DefinePlugin({
            'process.env': {
                'ENV': JSON.stringify(ENV)
            }
        })
    ]
});

tsconfig:

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "baseUrl": "",
    "moduleResolution": "node",
    "sourceMap": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": true,
    "noImplicitAny": false,
    "inlineSources": false,
    "rootDir": "./",
    "outDir": "../../../target/tscoutput"
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "awesomeTypescriptLoaderOptions": {
    "forkChecker": true,
    "useWebpackText": true
  }
}

我有这些版本的工具:

angular: 4.1.2 
@ngtools/webpack: 1.3.1 
webpack: 2.2.0

0 个答案:

没有答案