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')
20 const ExtractTextPlugin
= require('extract-text-webpack-plugin')
25 const ENV
= process
.env
.NODE_ENV
= process
.env
.ENV
= 'production'
26 const HOST
= process
.env
.HOST
|| 'localhost'
27 const PORT
= process
.env
.PORT
|| 8080
28 const AOT
= process
.env
.BUILD_AOT
|| helpers
.hasNpmFlag('aot')
38 module
.exports = function (env
) {
40 videoEmbedConfig({ env: ENV
}),
42 webpackMerge(commonConfig({ env: ENV
}), {
44 * Developer tool to enhance debugging
46 * See: http://webpack.github.io/docs/configuration.html#devtool
47 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
49 devtool: 'source-map',
52 * Options affecting the output of the compilation.
54 * See: http://webpack.github.io/docs/configuration.html#output
59 * The output directory as absolute path (required).
61 * See: http://webpack.github.io/docs/configuration.html#output-path
63 path: helpers
.root('dist'),
66 * Specifies the name of each output file on disk.
67 * IMPORTANT: You must not specify an absolute path here!
69 * See: http://webpack.github.io/docs/configuration.html#output-filename
71 filename: '[name].[chunkhash].bundle.js',
74 * The filename of the SourceMaps for the JavaScript files.
75 * They are inside the output.path directory.
77 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
79 sourceMapFilename: '[file].map',
82 * The filename of non-entry chunks as relative path
83 * inside the output.path directory.
85 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
87 chunkFilename: '[name].[chunkhash].chunk.js',
89 publicPath: '/client/'
95 test: /junk\/index\.js$/,
96 // exclude: /(node_modules|bower_components)/,
98 loader: 'babel-loader',
108 * Add additional plugins to the compiler.
110 * See: http://webpack.github.io/docs/configuration.html#plugins
115 * Webpack plugin to optimize a JavaScript file for faster initial load
116 * by wrapping eagerly-invoked functions.
118 * See: https://github.com/vigneshshanmugam/optimize-js-plugin
121 new OptimizeJsPlugin({
125 new ExtractTextPlugin({
126 filename: '[name].[contenthash].css',
131 * Plugin: DefinePlugin
132 * Description: Define free variables.
133 * Useful for having development builds with debug logging or adding global constants.
135 * Environment helpers
137 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
139 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
141 'ENV': JSON
.stringify(METADATA
.ENV
),
143 'API_URL': JSON
.stringify(METADATA
.API_URL
),
145 'process.version': JSON
.stringify(process
.version
),
146 'process.env.ENV': JSON
.stringify(METADATA
.ENV
),
147 'process.env.NODE_ENV': JSON
.stringify(METADATA
.ENV
),
148 'process.env.HMR': METADATA
.HMR
152 * Plugin: UglifyJsPlugin
153 * Description: Minimize all JavaScript output of chunks.
154 * Loaders are switched into minimizing mode.
156 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
173 * Plugin: NormalModuleReplacementPlugin
174 * Description: Replace resources that matches resourceRegExp with newResource
176 * See: http://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
178 new NormalModuleReplacementPlugin(
179 /(angular2|@angularclass)((\\|\/)|-)hmr/,
180 helpers
.root('config/empty.js')
183 new NormalModuleReplacementPlugin(
184 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
185 helpers
.root('config/empty.js')
188 new HashedModuleIdsPlugin(),
194 new NormalModuleReplacementPlugin(
195 /@angular(\\|\/)compiler/,
196 helpers
.root('config/empty.js')
198 ) : (new LoaderOptionsPlugin({}))),
201 * Plugin LoaderOptionsPlugin (experimental)
203 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
205 new LoaderOptionsPlugin({
211 * Static analysis linter for TypeScript advanced options configuration
212 * Description: An extensible linter for the TypeScript language.
214 * See: https://github.com/wbuchwalter/tslint-loader
223 * Html loader advanced options
225 * See: https://github.com/webpack/html-loader#advanced-options
227 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
230 removeAttributeQuotes: false,
232 customAttrSurround: [
237 customAttrAssign: [/\)?]?=/]
241 // https://github.com/bholloway/resolve-url-loader/issues/36
242 // https://github.com/jtangelder/sass-loader/issues/289
245 path: helpers
.root('dist')
250 new BundleAnalyzerPlugin({
251 // Can be `server`, `static` or `disabled`.
252 // In `server` mode analyzer will start HTTP server to show bundle report.
253 // In `static` mode single HTML file with bundle report will be generated.
254 // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
255 analyzerMode: 'static',
256 // Path to bundle report file that will be generated in `static` mode.
257 // Relative to bundles output directory.
258 reportFilename: 'report.html',
259 // Automatically open report in default browser
261 // If `true`, Webpack Stats JSON file will be generated in bundles output directory
262 generateStatsFile: true,
263 // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
264 // Relative to bundles output directory.
265 statsFilename: 'stats.json',
266 // Options for `stats.toJson()` method.
267 // For example you can exclude sources of your modules from stats file with `source: false` option.
268 // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
270 // Log level. Can be 'info', 'warn', 'error' or 'silent'.
276 * Include polyfills or mocks for various node stuff
277 * Description: Node configuration
279 * See: https://webpack.github.io/docs/configuration.html#node
287 clearImmediate: false,