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 ExtractTextPlugin
= require('extract-text-webpack-plugin')
14 const IgnorePlugin
= require('webpack/lib/IgnorePlugin')
15 const LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
16 const NormalModuleReplacementPlugin
= require('webpack/lib/NormalModuleReplacementPlugin')
17 const ProvidePlugin
= require('webpack/lib/ProvidePlugin')
18 const UglifyJsPlugin
= require('webpack/lib/optimize/UglifyJsPlugin')
19 const WebpackMd5Hash
= require('webpack-md5-hash')
20 const V8LazyParseWebpackPlugin
= require('v8-lazy-parse-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 METADATA
= webpackMerge(commonConfig({env: ENV
}).metadata
, {
35 module
.exports = function (env
) {
36 return webpackMerge(commonConfig({env: ENV
}), {
38 * Developer tool to enhance debugging
40 * See: http://webpack.github.io/docs/configuration.html#devtool
41 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
43 devtool: 'source-map',
46 * Options affecting the output of the compilation.
48 * See: http://webpack.github.io/docs/configuration.html#output
53 * The output directory as absolute path (required).
55 * See: http://webpack.github.io/docs/configuration.html#output-path
57 path: helpers
.root('dist'),
60 * Specifies the name of each output file on disk.
61 * IMPORTANT: You must not specify an absolute path here!
63 * See: http://webpack.github.io/docs/configuration.html#output-filename
65 filename: '[name].[chunkhash].bundle.js',
68 * The filename of the SourceMaps for the JavaScript files.
69 * They are inside the output.path directory.
71 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
73 sourceMapFilename: '[name].[chunkhash].bundle.map',
76 * The filename of non-entry chunks as relative path
77 * inside the output.path directory.
79 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
81 chunkFilename: '[id].[chunkhash].chunk.js',
83 publicPath: '/client/'
87 webtorrent: 'WebTorrent'
91 * Add additional plugins to the compiler.
93 * See: http://webpack.github.io/docs/configuration.html#plugins
98 * Plugin: WebpackMd5Hash
99 * Description: Plugin to replace a standard webpack chunkhash with md5.
101 * See: https://www.npmjs.com/package/webpack-md5-hash
103 new WebpackMd5Hash(),
106 * Plugin: DedupePlugin
107 * Description: Prevents the inclusion of duplicate code into your bundle
108 * and instead applies a copy of the function at runtime.
110 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
111 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
113 // new DedupePlugin(),
116 * Plugin: DefinePlugin
117 * Description: Define free variables.
118 * Useful for having development builds with debug logging or adding global constants.
120 * Environment helpers
122 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
124 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
126 'ENV': JSON
.stringify(METADATA
.ENV
),
129 'ENV': JSON
.stringify(METADATA
.ENV
),
130 'NODE_ENV': JSON
.stringify(METADATA
.ENV
),
135 * Plugin: UglifyJsPlugin
136 * Description: Minimize all JavaScript output of chunks.
137 * Loaders are switched into minimizing mode.
139 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
141 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
143 // beautify: true, //debug
144 // mangle: false, //debug
145 // dead_code: false, //debug
146 // unused: false, //debug
147 // deadCode: false, //debug
150 // keep_fnames: true,
151 // drop_debugger: false,
155 // comments: true, //debug
157 beautify: false, // prod
175 negate_iife: false // we need this for lazy v8
179 new NormalModuleReplacementPlugin(
181 helpers
.root('config/empty.js')
184 new NormalModuleReplacementPlugin(
185 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
186 helpers
.root('config/empty.js')
190 // new NormalModuleReplacementPlugin(
191 // /@angular(\\|\/)upgrade/,
192 // helpers.root('config/empty.js')
194 // new NormalModuleReplacementPlugin(
195 // /@angular(\\|\/)compiler/,
196 // helpers.root('config/empty.js')
198 // new NormalModuleReplacementPlugin(
199 // /@angular(\\|\/)platform-browser-dynamic/,
200 // helpers.root('config/empty.js')
202 // new NormalModuleReplacementPlugin(
203 // /dom(\\|\/)debug(\\|\/)ng_probe/,
204 // helpers.root('config/empty.js')
206 // new NormalModuleReplacementPlugin(
207 // /dom(\\|\/)debug(\\|\/)by/,
208 // helpers.root('config/empty.js')
210 // new NormalModuleReplacementPlugin(
211 // /src(\\|\/)debug(\\|\/)debug_node/,
212 // helpers.root('config/empty.js')
214 // new NormalModuleReplacementPlugin(
215 // /src(\\|\/)debug(\\|\/)debug_renderer/,
216 // helpers.root('config/empty.js')
220 * Plugin: IgnorePlugin
221 * Description: Don’t generate modules for requests matching the provided RegExp.
223 * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin
226 // new IgnorePlugin(/angular2-hmr/),
229 * Plugin: CompressionPlugin
230 * Description: Prepares compressed versions of assets to serve
231 * them with Content-Encoding
233 * See: https://github.com/webpack/compression-webpack-plugin
235 // install compression-webpack-plugin
236 // new CompressionPlugin({
237 // regExp: /\.css$|\.html$|\.js$|\.map$/,
238 // threshold: 2 * 1024
242 * Plugin LoaderOptionsPlugin (experimental)
244 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
246 new LoaderOptionsPlugin({
251 * Static analysis linter for TypeScript advanced options configuration
252 * Description: An extensible linter for the TypeScript language.
254 * See: https://github.com/wbuchwalter/tslint-loader
263 * Html loader advanced options
265 * See: https://github.com/webpack/html-loader#advanced-options
267 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
270 removeAttributeQuotes: false,
272 customAttrSurround: [
277 customAttrAssign: [/\)?\]?=/]
281 // https://github.com/bholloway/resolve-url-loader/issues/36
282 // https://github.com/jtangelder/sass-loader/issues/289
285 path: helpers
.root('dist')
292 * Include polyfills or mocks for various node stuff
293 * Description: Node configuration
295 * See: https://webpack.github.io/docs/configuration.html#node
302 clearImmediate: false,