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 UglifyJsPlugin
= require('webpack/lib/optimize/UglifyJsPlugin')
16 const WebpackMd5Hash
= require('webpack-md5-hash')
21 const ENV
= process
.env
.NODE_ENV
= process
.env
.ENV
= 'production'
22 const HOST
= process
.env
.HOST
|| 'localhost'
23 const PORT
= process
.env
.PORT
|| 8080
24 const METADATA
= webpackMerge(commonConfig({env: ENV
}).metadata
, {
31 module
.exports = function (env
) {
32 return webpackMerge(commonConfig({env: ENV
}), {
34 * Developer tool to enhance debugging
36 * See: http://webpack.github.io/docs/configuration.html#devtool
37 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
39 devtool: 'source-map',
42 * Options affecting the output of the compilation.
44 * See: http://webpack.github.io/docs/configuration.html#output
49 * The output directory as absolute path (required).
51 * See: http://webpack.github.io/docs/configuration.html#output-path
53 path: helpers
.root('dist'),
56 * Specifies the name of each output file on disk.
57 * IMPORTANT: You must not specify an absolute path here!
59 * See: http://webpack.github.io/docs/configuration.html#output-filename
61 filename: '[name].[chunkhash].bundle.js',
64 * The filename of the SourceMaps for the JavaScript files.
65 * They are inside the output.path directory.
67 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
69 sourceMapFilename: '[name].[chunkhash].bundle.map',
72 * The filename of non-entry chunks as relative path
73 * inside the output.path directory.
75 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
77 chunkFilename: '[id].[chunkhash].chunk.js',
79 publicPath: '/client/'
83 webtorrent: 'WebTorrent'
87 * Add additional plugins to the compiler.
89 * See: http://webpack.github.io/docs/configuration.html#plugins
94 * Plugin: WebpackMd5Hash
95 * Description: Plugin to replace a standard webpack chunkhash with md5.
97 * See: https://www.npmjs.com/package/webpack-md5-hash
102 * Plugin: DedupePlugin
103 * Description: Prevents the inclusion of duplicate code into your bundle
104 * and instead applies a copy of the function at runtime.
106 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
107 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
109 // new DedupePlugin(),
112 * Plugin: DefinePlugin
113 * Description: Define free variables.
114 * Useful for having development builds with debug logging or adding global constants.
116 * Environment helpers
118 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
120 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
122 'ENV': JSON
.stringify(METADATA
.ENV
),
125 'ENV': JSON
.stringify(METADATA
.ENV
),
126 'NODE_ENV': JSON
.stringify(METADATA
.ENV
),
131 * Plugin: UglifyJsPlugin
132 * Description: Minimize all JavaScript output of chunks.
133 * Loaders are switched into minimizing mode.
135 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
137 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
139 // beautify: true, //debug
140 // mangle: false, //debug
141 // dead_code: false, //debug
142 // unused: false, //debug
143 // deadCode: false, //debug
146 // keep_fnames: true,
147 // drop_debugger: false,
151 // comments: true, //debug
153 beautify: false, // prod
171 negate_iife: false // we need this for lazy v8
175 new NormalModuleReplacementPlugin(
177 helpers
.root('config/empty.js')
180 new NormalModuleReplacementPlugin(
181 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
182 helpers
.root('config/empty.js')
186 // new NormalModuleReplacementPlugin(
187 // /@angular(\\|\/)upgrade/,
188 // helpers.root('config/empty.js')
190 // new NormalModuleReplacementPlugin(
191 // /@angular(\\|\/)compiler/,
192 // helpers.root('config/empty.js')
194 // new NormalModuleReplacementPlugin(
195 // /@angular(\\|\/)platform-browser-dynamic/,
196 // helpers.root('config/empty.js')
198 // new NormalModuleReplacementPlugin(
199 // /dom(\\|\/)debug(\\|\/)ng_probe/,
200 // helpers.root('config/empty.js')
202 // new NormalModuleReplacementPlugin(
203 // /dom(\\|\/)debug(\\|\/)by/,
204 // helpers.root('config/empty.js')
206 // new NormalModuleReplacementPlugin(
207 // /src(\\|\/)debug(\\|\/)debug_node/,
208 // helpers.root('config/empty.js')
210 // new NormalModuleReplacementPlugin(
211 // /src(\\|\/)debug(\\|\/)debug_renderer/,
212 // helpers.root('config/empty.js')
216 * Plugin: IgnorePlugin
217 * Description: Don’t generate modules for requests matching the provided RegExp.
219 * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin
222 // new IgnorePlugin(/angular2-hmr/),
225 * Plugin: CompressionPlugin
226 * Description: Prepares compressed versions of assets to serve
227 * them with Content-Encoding
229 * See: https://github.com/webpack/compression-webpack-plugin
231 // install compression-webpack-plugin
232 // new CompressionPlugin({
233 // regExp: /\.css$|\.html$|\.js$|\.map$/,
234 // threshold: 2 * 1024
238 * Plugin LoaderOptionsPlugin (experimental)
240 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
242 new LoaderOptionsPlugin({
247 * Static analysis linter for TypeScript advanced options configuration
248 * Description: An extensible linter for the TypeScript language.
250 * See: https://github.com/wbuchwalter/tslint-loader
259 * Html loader advanced options
261 * See: https://github.com/webpack/html-loader#advanced-options
263 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
266 removeAttributeQuotes: false,
268 customAttrSurround: [
273 customAttrAssign: [/\)?]?=/]
277 // https://github.com/bholloway/resolve-url-loader/issues/36
278 // https://github.com/jtangelder/sass-loader/issues/289
281 path: helpers
.root('dist')
288 * Include polyfills or mocks for various node stuff
289 * Description: Node configuration
291 * See: https://webpack.github.io/docs/configuration.html#node
298 clearImmediate: false,