Created
December 3, 2017 13:58
-
-
Save phoenisx/264e07e04a736fd50d1c7d7906aaf76d to your computer and use it in GitHub Desktop.
Angular AOT Build with @ngtools/webapck, STEP II
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"start:prod:test": "npm-run-all clean build:prod:test change:hbs", | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webpack = require('webpack'); | |
const webpackMerge = require('webpack-merge'); | |
const CleanWebpackPlugin = require('clean-webpack-plugin'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const commonConfig = require('./webpack.common'); | |
const { ENV, dir, IS_PRODUCTION } = require('./helpers'); | |
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; | |
const ngtools = require('@ngtools/webpack'); | |
var environment = require('../src/environments/environment.prod'); | |
module.exports = function(env) { | |
var _plugins = [ | |
new ngtools.AotPlugin({ | |
tsConfigPath: 'tsconfig-aot.json', | |
entryModule: dir('src', 'app', 'app.module#AppModule'), | |
sourceMap: false | |
}), | |
new webpack.ContextReplacementPlugin( | |
// The (\\|\/) piece accounts for path separators in *nix and Windows | |
/angular(\\|\/)core(\\|\/)@angular/, | |
dir('src') | |
), | |
// Disable this when Checking for Bundle Analysis... | |
// new webpack.optimize.ModuleConcatenationPlugin(), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: ['datatable', 'main', 'polyfills'], | |
minChunks: Infinity | |
}), | |
new HtmlWebpackPlugin({ | |
template: 'src/index.html', | |
chunksSortMode: 'dependency', | |
title: 'Quick Reports' | |
}), | |
new CleanWebpackPlugin(['server/dist'], { | |
root: dir(), | |
verbose: false, | |
dry: false | |
}), | |
new webpack.optimize.UglifyJsPlugin({ | |
compress: { warnings: false } | |
}) | |
]; | |
if (IS_PRODUCTION || true) { | |
_plugins.push( new BundleAnalyzerPlugin(bundleAnalyzerOpt) ); | |
} | |
return webpackMerge(commonConfig({ env: ENV, environment: environment }), { | |
devtool: 'source-map', | |
entry: { | |
'app': './src/bootstrap.aot.ts', | |
'polyfills': './src/polyfills.ts' | |
}, | |
module: { | |
exprContextCritical: false, | |
rules: [ | |
{ | |
test: /\.ts$/, | |
loader: '@ngtools/webpack', | |
exclude: [/\.(spec|e2e|d)\.ts$/] | |
} | |
] | |
}, | |
plugins: _plugins | |
}); | |
}; | |
bundleAnalyzerOpt = { | |
analyzerMode: 'server', | |
analyzerHost: '127.0.0.1', | |
analyzerPort: 8888, | |
reportFilename: dir('stats','report.html'), | |
defaultSizes: 'parsed', | |
generateStatsFile: true, | |
statsFilename: dir('stats', 'stats.json'), | |
logLevel: 'warn' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment