2 * @author: @AngularClass
5 const helpers
= require('./helpers')
6 const webpackMerge
= require('webpack-merge') // used to merge webpack configs
7 const commonConfig
= require('./webpack.common.js') // the settings that are common to prod and dev
8 const videoEmbedConfig
= require('./webpack.video-embed.js')
13 const DefinePlugin
= require('webpack/lib/DefinePlugin')
14 const BundleAnalyzerPlugin
= require('webpack-bundle-analyzer').BundleAnalyzerPlugin
15 const LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
16 const NormalModuleReplacementPlugin
= require('webpack/lib/NormalModuleReplacementPlugin')
17 const OptimizeJsPlugin
= require('optimize-js-plugin')
18 const HashedModuleIdsPlugin
= require('webpack/lib/HashedModuleIdsPlugin')
19 const UglifyJsPlugin
= require('uglifyjs-webpack-plugin')
23 const ENV
= process
.env
.NODE_ENV
= process
.env
.ENV
= 'production'
24 const HOST
= process
.env
.HOST
|| 'localhost'
25 const PORT
= process
.env
.PORT
|| 8080
26 const AOT
= process
.env
.BUILD_AOT
|| helpers
.hasNpmFlag('aot')
36 module
.exports = function (env
) {
38 videoEmbedConfig({ env: ENV
}),
40 webpackMerge(commonConfig({ env: ENV
}), {
42 * Developer tool to enhance debugging
44 * See: http://webpack.github.io/docs/configuration.html#devtool
45 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
47 devtool: 'source-map',
50 * Options affecting the output of the compilation.
52 * See: http://webpack.github.io/docs/configuration.html#output
57 * The output directory as absolute path (required).
59 * See: http://webpack.github.io/docs/configuration.html#output-path
61 path: helpers
.root('dist'),
64 * Specifies the name of each output file on disk.
65 * IMPORTANT: You must not specify an absolute path here!
67 * See: http://webpack.github.io/docs/configuration.html#output-filename
69 filename: '[name].[chunkhash].bundle.js',
72 * The filename of the SourceMaps for the JavaScript files.
73 * They are inside the output.path directory.
75 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
77 sourceMapFilename: '[file].map',
80 * The filename of non-entry chunks as relative path
81 * inside the output.path directory.
83 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
85 chunkFilename: '[name].[chunkhash].chunk.js',
87 publicPath: '/client/'
93 test: /junk\/index\.js$/,
94 // exclude: /(node_modules|bower_components)/,
96 loader: 'babel-loader',
106 * Add additional plugins to the compiler.
108 * See: http://webpack.github.io/docs/configuration.html#plugins
113 * Webpack plugin to optimize a JavaScript file for faster initial load
114 * by wrapping eagerly-invoked functions.
116 * See: https://github.com/vigneshshanmugam/optimize-js-plugin
119 new OptimizeJsPlugin({
124 * Plugin: DedupePlugin
125 * Description: Prevents the inclusion of duplicate code into your bundle
126 * and instead applies a copy of the function at runtime.
128 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
129 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
131 // new DedupePlugin(),
134 * Plugin: DefinePlugin
135 * Description: Define free variables.
136 * Useful for having development builds with debug logging or adding global constants.
138 * Environment helpers
140 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
142 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
144 'ENV': JSON
.stringify(METADATA
.ENV
),
146 'API_URL': JSON
.stringify(METADATA
.API_URL
),
148 'process.version': JSON
.stringify(process
.version
),
149 'process.env.ENV': JSON
.stringify(METADATA
.ENV
),
150 'process.env.NODE_ENV': JSON
.stringify(METADATA
.ENV
),
151 'process.env.HMR': METADATA
.HMR
155 * Plugin: UglifyJsPlugin
156 * Description: Minimize all JavaScript output of chunks.
157 * Loaders are switched into minimizing mode.
159 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
161 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
178 * Plugin: NormalModuleReplacementPlugin
179 * Description: Replace resources that matches resourceRegExp with newResource
181 * See: http://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
183 new NormalModuleReplacementPlugin(
184 /(angular2|@angularclass)((\\|\/)|-)hmr/,
185 helpers
.root('config/empty.js')
188 new NormalModuleReplacementPlugin(
189 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
190 helpers
.root('config/empty.js')
193 new HashedModuleIdsPlugin(),
199 new NormalModuleReplacementPlugin(
200 /@angular(\\|\/)compiler/,
201 helpers
.root('config/empty.js')
203 ) : (new LoaderOptionsPlugin({}))),
206 * Plugin LoaderOptionsPlugin (experimental)
208 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
210 new LoaderOptionsPlugin({
216 * Static analysis linter for TypeScript advanced options configuration
217 * Description: An extensible linter for the TypeScript language.
219 * See: https://github.com/wbuchwalter/tslint-loader
228 * Html loader advanced options
230 * See: https://github.com/webpack/html-loader#advanced-options
232 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
235 removeAttributeQuotes: false,
237 customAttrSurround: [
242 customAttrAssign: [/\)?]?=/]
246 // https://github.com/bholloway/resolve-url-loader/issues/36
247 // https://github.com/jtangelder/sass-loader/issues/289
250 path: helpers
.root('dist')
255 new BundleAnalyzerPlugin({
256 // Can be `server`, `static` or `disabled`.
257 // In `server` mode analyzer will start HTTP server to show bundle report.
258 // In `static` mode single HTML file with bundle report will be generated.
259 // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
260 analyzerMode: 'static',
261 // Path to bundle report file that will be generated in `static` mode.
262 // Relative to bundles output directory.
263 reportFilename: 'report.html',
264 // Automatically open report in default browser
266 // If `true`, Webpack Stats JSON file will be generated in bundles output directory
267 generateStatsFile: true,
268 // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
269 // Relative to bundles output directory.
270 statsFilename: 'stats.json',
271 // Options for `stats.toJson()` method.
272 // For example you can exclude sources of your modules from stats file with `source: false` option.
273 // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
275 // Log level. Can be 'info', 'warn', 'error' or 'silent'.
281 * Include polyfills or mocks for various node stuff
282 * Description: Node configuration
284 * See: https://webpack.github.io/docs/configuration.html#node
292 clearImmediate: false,