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 HashedModuleIdsPlugin
= require('webpack/lib/HashedModuleIdsPlugin')
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
, {
33 module
.exports = function (env
) {
34 return webpackMerge(commonConfig({env: ENV
}), {
36 * Developer tool to enhance debugging
38 * See: http://webpack.github.io/docs/configuration.html#devtool
39 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
41 devtool: 'source-map',
44 * Options affecting the output of the compilation.
46 * See: http://webpack.github.io/docs/configuration.html#output
51 * The output directory as absolute path (required).
53 * See: http://webpack.github.io/docs/configuration.html#output-path
55 path: helpers
.root('dist'),
58 * Specifies the name of each output file on disk.
59 * IMPORTANT: You must not specify an absolute path here!
61 * See: http://webpack.github.io/docs/configuration.html#output-filename
63 filename: '[name].[chunkhash].bundle.js',
66 * The filename of the SourceMaps for the JavaScript files.
67 * They are inside the output.path directory.
69 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
71 sourceMapFilename: '[file].map',
74 * The filename of non-entry chunks as relative path
75 * inside the output.path directory.
77 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
79 chunkFilename: '[name].[chunkhash].chunk.js',
81 publicPath: '/client/'
87 test: /junk\/index\.js$/,
88 // exclude: /(node_modules|bower_components)/,
90 loader: 'babel-loader',
100 * Add additional plugins to the compiler.
102 * See: http://webpack.github.io/docs/configuration.html#plugins
107 * Webpack plugin to optimize a JavaScript file for faster initial load
108 * by wrapping eagerly-invoked functions.
110 * See: https://github.com/vigneshshanmugam/optimize-js-plugin
113 new OptimizeJsPlugin({
118 * Plugin: DedupePlugin
119 * Description: Prevents the inclusion of duplicate code into your bundle
120 * and instead applies a copy of the function at runtime.
122 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
123 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
125 // new DedupePlugin(),
128 * Plugin: DefinePlugin
129 * Description: Define free variables.
130 * Useful for having development builds with debug logging or adding global constants.
132 * Environment helpers
134 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
136 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
138 'ENV': JSON
.stringify(METADATA
.ENV
),
140 'API_URL': JSON
.stringify(METADATA
.API_URL
),
141 'process.version': JSON
.stringify(process
.version
),
143 'ENV': JSON
.stringify(METADATA
.ENV
),
144 'NODE_ENV': JSON
.stringify(METADATA
.ENV
),
150 * Plugin: UglifyJsPlugin
151 * Description: Minimize all JavaScript output of chunks.
152 * Loaders are switched into minimizing mode.
154 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
156 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
158 // beautify: true, //debug
159 // mangle: false, //debug
160 // dead_code: false, //debug
161 // unused: false, //debug
162 // deadCode: false, //debug
165 // keep_fnames: true,
166 // drop_debugger: false,
170 // comments: true, //debug
172 beautify: false, // prod
190 negate_iife: false // we need this for lazy v8
194 new NormalModuleReplacementPlugin(
196 helpers
.root('config/empty.js')
199 new NormalModuleReplacementPlugin(
200 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
201 helpers
.root('config/empty.js')
204 new HashedModuleIdsPlugin(),
207 * Plugin: IgnorePlugin
208 * Description: Don’t generate modules for requests matching the provided RegExp.
210 * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin
213 // new IgnorePlugin(/angular2-hmr/),
216 * Plugin: CompressionPlugin
217 * Description: Prepares compressed versions of assets to serve
218 * them with Content-Encoding
220 * See: https://github.com/webpack/compression-webpack-plugin
222 // install compression-webpack-plugin
223 // new CompressionPlugin({
224 // regExp: /\.css$|\.html$|\.js$|\.map$/,
225 // threshold: 2 * 1024
229 * Plugin LoaderOptionsPlugin (experimental)
231 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
233 new LoaderOptionsPlugin({
239 * Static analysis linter for TypeScript advanced options configuration
240 * Description: An extensible linter for the TypeScript language.
242 * See: https://github.com/wbuchwalter/tslint-loader
251 * Html loader advanced options
253 * See: https://github.com/webpack/html-loader#advanced-options
255 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
258 removeAttributeQuotes: false,
260 customAttrSurround: [
265 customAttrAssign: [/\)?]?=/]
269 // https://github.com/bholloway/resolve-url-loader/issues/36
270 // https://github.com/jtangelder/sass-loader/issues/289
273 path: helpers
.root('dist')
280 * Include polyfills or mocks for various node stuff
281 * Description: Node configuration
283 * See: https://webpack.github.io/docs/configuration.html#node
291 clearImmediate: false,