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
12 const DefinePlugin
= require('webpack/lib/DefinePlugin')
13 const LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
14 const NormalModuleReplacementPlugin
= require('webpack/lib/NormalModuleReplacementPlugin')
15 const OptimizeJsPlugin
= require('optimize-js-plugin')
16 const UglifyJsPlugin
= require('webpack/lib/optimize/UglifyJsPlugin')
17 const WebpackMd5Hash
= require('webpack-md5-hash')
22 const ENV
= process
.env
.NODE_ENV
= process
.env
.ENV
= 'production'
23 const HOST
= process
.env
.HOST
|| 'localhost'
24 const PORT
= process
.env
.PORT
|| 8080
25 const METADATA
= webpackMerge(commonConfig({env: ENV
}).metadata
, {
32 module
.exports = function (env
) {
33 return webpackMerge(commonConfig({env: ENV
}), {
35 * Developer tool to enhance debugging
37 * See: http://webpack.github.io/docs/configuration.html#devtool
38 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
40 devtool: 'source-map',
43 * Options affecting the output of the compilation.
45 * See: http://webpack.github.io/docs/configuration.html#output
50 * The output directory as absolute path (required).
52 * See: http://webpack.github.io/docs/configuration.html#output-path
54 path: helpers
.root('dist'),
57 * Specifies the name of each output file on disk.
58 * IMPORTANT: You must not specify an absolute path here!
60 * See: http://webpack.github.io/docs/configuration.html#output-filename
62 filename: '[name].[chunkhash].bundle.js',
65 * The filename of the SourceMaps for the JavaScript files.
66 * They are inside the output.path directory.
68 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
70 sourceMapFilename: '[name].[chunkhash].bundle.map',
73 * The filename of non-entry chunks as relative path
74 * inside the output.path directory.
76 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
78 chunkFilename: '[id].[chunkhash].chunk.js',
80 publicPath: '/client/'
84 webtorrent: 'WebTorrent'
88 * Add additional plugins to the compiler.
90 * See: http://webpack.github.io/docs/configuration.html#plugins
95 * Plugin: WebpackMd5Hash
96 * Description: Plugin to replace a standard webpack chunkhash with md5.
98 * See: https://www.npmjs.com/package/webpack-md5-hash
100 new WebpackMd5Hash(),
103 * Webpack plugin to optimize a JavaScript file for faster initial load
104 * by wrapping eagerly-invoked functions.
106 * See: https://github.com/vigneshshanmugam/optimize-js-plugin
109 new OptimizeJsPlugin({
114 * Plugin: DedupePlugin
115 * Description: Prevents the inclusion of duplicate code into your bundle
116 * and instead applies a copy of the function at runtime.
118 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
119 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
121 // new DedupePlugin(),
124 * Plugin: DefinePlugin
125 * Description: Define free variables.
126 * Useful for having development builds with debug logging or adding global constants.
128 * Environment helpers
130 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
132 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
134 'ENV': JSON
.stringify(METADATA
.ENV
),
137 'ENV': JSON
.stringify(METADATA
.ENV
),
138 'NODE_ENV': JSON
.stringify(METADATA
.ENV
),
143 * Plugin: UglifyJsPlugin
144 * Description: Minimize all JavaScript output of chunks.
145 * Loaders are switched into minimizing mode.
147 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
149 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
151 // beautify: true, //debug
152 // mangle: false, //debug
153 // dead_code: false, //debug
154 // unused: false, //debug
155 // deadCode: false, //debug
158 // keep_fnames: true,
159 // drop_debugger: false,
163 // comments: true, //debug
165 beautify: false, // prod
183 negate_iife: false // we need this for lazy v8
187 new NormalModuleReplacementPlugin(
189 helpers
.root('config/empty.js')
192 new NormalModuleReplacementPlugin(
193 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
194 helpers
.root('config/empty.js')
198 // new NormalModuleReplacementPlugin(
199 // /@angular(\\|\/)upgrade/,
200 // helpers.root('config/empty.js')
202 // new NormalModuleReplacementPlugin(
203 // /@angular(\\|\/)compiler/,
204 // helpers.root('config/empty.js')
206 // new NormalModuleReplacementPlugin(
207 // /@angular(\\|\/)platform-browser-dynamic/,
208 // helpers.root('config/empty.js')
210 // new NormalModuleReplacementPlugin(
211 // /dom(\\|\/)debug(\\|\/)ng_probe/,
212 // helpers.root('config/empty.js')
214 // new NormalModuleReplacementPlugin(
215 // /dom(\\|\/)debug(\\|\/)by/,
216 // helpers.root('config/empty.js')
218 // new NormalModuleReplacementPlugin(
219 // /src(\\|\/)debug(\\|\/)debug_node/,
220 // helpers.root('config/empty.js')
222 // new NormalModuleReplacementPlugin(
223 // /src(\\|\/)debug(\\|\/)debug_renderer/,
224 // helpers.root('config/empty.js')
228 * Plugin: IgnorePlugin
229 * Description: Don’t generate modules for requests matching the provided RegExp.
231 * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin
234 // new IgnorePlugin(/angular2-hmr/),
237 * Plugin: CompressionPlugin
238 * Description: Prepares compressed versions of assets to serve
239 * them with Content-Encoding
241 * See: https://github.com/webpack/compression-webpack-plugin
243 // install compression-webpack-plugin
244 // new CompressionPlugin({
245 // regExp: /\.css$|\.html$|\.js$|\.map$/,
246 // threshold: 2 * 1024
250 * Plugin LoaderOptionsPlugin (experimental)
252 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
254 new LoaderOptionsPlugin({
259 * Static analysis linter for TypeScript advanced options configuration
260 * Description: An extensible linter for the TypeScript language.
262 * See: https://github.com/wbuchwalter/tslint-loader
271 * Html loader advanced options
273 * See: https://github.com/webpack/html-loader#advanced-options
275 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
278 removeAttributeQuotes: false,
280 customAttrSurround: [
285 customAttrAssign: [/\)?]?=/]
289 // https://github.com/bholloway/resolve-url-loader/issues/36
290 // https://github.com/jtangelder/sass-loader/issues/289
293 path: helpers
.root('dist')
300 * Include polyfills or mocks for various node stuff
301 * Description: Node configuration
303 * See: https://webpack.github.io/docs/configuration.html#node
310 clearImmediate: false,