2016-11-29 11:42:17 +01:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const path = require('path');
|
|
|
|
const clone = require('js.clone');
|
|
|
|
const webpackMerge = require('webpack-merge');
|
|
|
|
const V8LazyParseWebpackPlugin = require('v8-lazy-parse-webpack-plugin');
|
2016-11-22 14:36:12 +01:00
|
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
|
|
import webpackConfig, { root, includeClientPackages } from './webpack.config';
|
2016-11-29 11:42:17 +01:00
|
|
|
// const CompressionPlugin = require('compression-webpack-plugin');
|
2016-11-22 14:36:12 +01:00
|
|
|
|
|
|
|
|
2016-11-29 11:42:17 +01:00
|
|
|
export const commonPlugins = [
|
2016-11-22 14:36:12 +01:00
|
|
|
new V8LazyParseWebpackPlugin(),
|
|
|
|
|
|
|
|
new webpack.DefinePlugin({
|
2016-12-09 12:09:01 +01:00
|
|
|
// do not use an object for 'process.env' otherwise all other environment
|
|
|
|
// variables are set to 'undefined' see issue #291
|
|
|
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
|
|
'process.env.AOT': true
|
2016-11-22 14:36:12 +01:00
|
|
|
}),
|
|
|
|
|
|
|
|
// Loader options
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
minimize: true,
|
|
|
|
debug: false
|
|
|
|
}),
|
|
|
|
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/facade(\\|\/)async/,
|
|
|
|
root('node_modules/@angular/core/src/facade/async.js')
|
|
|
|
),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/facade(\\|\/)collection/,
|
|
|
|
root('node_modules/@angular/core/src/facade/collection.js')
|
|
|
|
),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/facade(\\|\/)errors/,
|
|
|
|
root('node_modules/@angular/core/src/facade/errors.js')
|
|
|
|
),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/facade(\\|\/)lang/,
|
|
|
|
root('node_modules/@angular/core/src/facade/lang.js')
|
|
|
|
),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/facade(\\|\/)math/,
|
|
|
|
root('node_modules/@angular/core/src/facade/math.js')
|
|
|
|
),
|
|
|
|
|
|
|
|
];
|
2016-11-29 11:42:17 +01:00
|
|
|
export const commonConfig = {
|
2016-11-22 14:36:12 +01:00
|
|
|
output: {
|
|
|
|
filename: '[name].bundle.js',
|
|
|
|
chunkFilename: '[chunkhash].js'
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Client.
|
2016-11-29 11:42:17 +01:00
|
|
|
export const clientPlugins = [
|
2016-11-22 14:36:12 +01:00
|
|
|
new BundleAnalyzerPlugin({
|
2016-11-29 11:42:17 +01:00
|
|
|
analyzerMode: 'disabled', // change it to `server` to view bundle stats
|
2016-11-22 14:36:12 +01:00
|
|
|
reportFilename: 'report.html',
|
|
|
|
generateStatsFile: true,
|
|
|
|
statsFilename: 'stats.json',
|
|
|
|
}),
|
|
|
|
// To use gzip, you can run 'npm install compression-webpack-plugin --save-dev'
|
|
|
|
// add 'var CompressionPlugin = require("compression-webpack-plugin");' on the top
|
|
|
|
// and comment out below codes
|
|
|
|
//
|
|
|
|
// new CompressionPlugin({
|
|
|
|
// asset: "[path].gz[query]",
|
|
|
|
// algorithm: "gzip",
|
|
|
|
// test: /\.js$|\.css$|\.html$/,
|
|
|
|
// threshold: 10240,
|
|
|
|
// minRatio: 0.8
|
|
|
|
// }),
|
|
|
|
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
// beautify: true,
|
|
|
|
// mangle: false,
|
|
|
|
output: {
|
|
|
|
comments: false
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
warnings: false,
|
|
|
|
conditionals: true,
|
|
|
|
unused: true,
|
|
|
|
comparisons: true,
|
|
|
|
sequences: true,
|
|
|
|
dead_code: true,
|
|
|
|
evaluate: true,
|
|
|
|
if_return: true,
|
|
|
|
join_vars: true,
|
|
|
|
negate_iife: false // we need this for lazy v8
|
2016-11-29 11:42:17 +01:00
|
|
|
},
|
|
|
|
sourceMap: true
|
2016-11-22 14:36:12 +01:00
|
|
|
}),
|
|
|
|
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/@angular(\\|\/)upgrade/,
|
|
|
|
root('empty.js')
|
|
|
|
),
|
|
|
|
// problem with platformUniversalDynamic on the server/client
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/@angular(\\|\/)compiler/,
|
|
|
|
root('empty.js')
|
|
|
|
),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/@angular(\\|\/)platform-browser-dynamic/,
|
|
|
|
root('empty.js')
|
|
|
|
),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/dom(\\|\/)debug(\\|\/)ng_probe/,
|
|
|
|
root('empty.js')
|
|
|
|
),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/dom(\\|\/)debug(\\|\/)by/,
|
|
|
|
root('empty.js')
|
|
|
|
),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/src(\\|\/)debug(\\|\/)debug_node/,
|
|
|
|
root('empty.js')
|
|
|
|
),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/src(\\|\/)debug(\\|\/)debug_renderer/,
|
|
|
|
root('empty.js')
|
|
|
|
),
|
|
|
|
|
|
|
|
// Waiting for https://github.com/ampedandwired/html-webpack-plugin/issues/446
|
|
|
|
// new webpack.optimize.AggressiveSplittingPlugin({
|
|
|
|
// minSize: 30000,
|
|
|
|
// maxSize: 250000
|
|
|
|
// }),
|
|
|
|
|
|
|
|
];
|
2016-11-29 11:42:17 +01:00
|
|
|
export const clientConfig = {
|
2016-11-22 14:36:12 +01:00
|
|
|
entry: './src/client.aot',
|
|
|
|
recordsOutputPath: root('webpack.records.json')
|
|
|
|
};
|
|
|
|
|
|
|
|
// Server.
|
|
|
|
|
2016-11-29 11:42:17 +01:00
|
|
|
export const serverPlugins = [
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
// beautify: true,
|
|
|
|
mangle: false, // to ensure process.env still works
|
|
|
|
output: {
|
|
|
|
comments: false
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
warnings: false,
|
|
|
|
conditionals: true,
|
|
|
|
unused: true,
|
|
|
|
comparisons: true,
|
|
|
|
sequences: true,
|
|
|
|
dead_code: true,
|
|
|
|
evaluate: true,
|
|
|
|
if_return: true,
|
|
|
|
join_vars: true,
|
|
|
|
negate_iife: false // we need this for lazy v8
|
|
|
|
},
|
|
|
|
sourceMap: true
|
|
|
|
}),
|
2016-11-22 14:36:12 +01:00
|
|
|
];
|
2016-11-29 11:42:17 +01:00
|
|
|
export const serverConfig = {
|
2016-11-22 14:36:12 +01:00
|
|
|
entry: './src/server.aot',
|
|
|
|
output: {
|
2016-11-29 11:42:17 +01:00
|
|
|
filename: 'index.js',
|
|
|
|
chunkFilename: '[id].bundle.js',
|
|
|
|
crossOriginLoading: false
|
2016-11-22 14:36:12 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default [
|
|
|
|
// Client
|
|
|
|
webpackMerge(webpackConfig[0], clone(commonConfig), clientConfig, {plugins: webpackConfig[0].plugins.concat(commonPlugins, clientPlugins) }),
|
|
|
|
|
|
|
|
// Server
|
|
|
|
webpackMerge(webpackConfig[1], clone(commonConfig), serverConfig, {plugins: webpackConfig[1].plugins.concat(commonPlugins, serverPlugins) })
|
|
|
|
];
|