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 LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
15 const NormalModuleReplacementPlugin
= require('webpack/lib/NormalModuleReplacementPlugin')
16 const OptimizeJsPlugin
= require('optimize-js-plugin')
17 const UglifyJsPlugin
= require('webpack/lib/optimize/UglifyJsPlugin')
18 const HashedModuleIdsPlugin
= require('webpack/lib/HashedModuleIdsPlugin')
23 const ENV
= process
.env
.NODE_ENV
= process
.env
.ENV
= 'production'
24 const HOST
= process
.env
.HOST
|| 'localhost'
25 const PORT
= process
.env
.PORT
|| 8080
26 const METADATA
= webpackMerge(commonConfig({env: ENV
}).metadata
, {
34 module
.exports = function (env
) {
36 videoEmbedConfig({ env: ENV
}),
38 webpackMerge(commonConfig({ env: ENV
}), {
40 * Developer tool to enhance debugging
42 * See: http://webpack.github.io/docs/configuration.html#devtool
43 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
45 devtool: 'source-map',
48 * Options affecting the output of the compilation.
50 * See: http://webpack.github.io/docs/configuration.html#output
55 * The output directory as absolute path (required).
57 * See: http://webpack.github.io/docs/configuration.html#output-path
59 path: helpers
.root('dist'),
62 * Specifies the name of each output file on disk.
63 * IMPORTANT: You must not specify an absolute path here!
65 * See: http://webpack.github.io/docs/configuration.html#output-filename
67 filename: '[name].[chunkhash].bundle.js',
70 * The filename of the SourceMaps for the JavaScript files.
71 * They are inside the output.path directory.
73 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
75 sourceMapFilename: '[file].map',
78 * The filename of non-entry chunks as relative path
79 * inside the output.path directory.
81 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
83 chunkFilename: '[name].[chunkhash].chunk.js',
85 publicPath: '/client/'
91 test: /junk\/index\.js$/,
92 // exclude: /(node_modules|bower_components)/,
94 loader: 'babel-loader',
104 * Add additional plugins to the compiler.
106 * See: http://webpack.github.io/docs/configuration.html#plugins
111 * Webpack plugin to optimize a JavaScript file for faster initial load
112 * by wrapping eagerly-invoked functions.
114 * See: https://github.com/vigneshshanmugam/optimize-js-plugin
117 new OptimizeJsPlugin({
122 * Plugin: DedupePlugin
123 * Description: Prevents the inclusion of duplicate code into your bundle
124 * and instead applies a copy of the function at runtime.
126 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
127 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
129 // new DedupePlugin(),
132 * Plugin: DefinePlugin
133 * Description: Define free variables.
134 * Useful for having development builds with debug logging or adding global constants.
136 * Environment helpers
138 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
140 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
142 'ENV': JSON
.stringify(METADATA
.ENV
),
144 'API_URL': JSON
.stringify(METADATA
.API_URL
),
145 'process.version': JSON
.stringify(process
.version
),
147 'ENV': JSON
.stringify(METADATA
.ENV
),
148 'NODE_ENV': JSON
.stringify(METADATA
.ENV
),
154 * Plugin: UglifyJsPlugin
155 * Description: Minimize all JavaScript output of chunks.
156 * Loaders are switched into minimizing mode.
158 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
160 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
162 // beautify: true, //debug
163 // mangle: false, //debug
164 // dead_code: false, //debug
165 // unused: false, //debug
166 // deadCode: false, //debug
169 // keep_fnames: true,
170 // drop_debugger: false,
174 // comments: true, //debug
176 beautify: false, // prod
194 negate_iife: false // we need this for lazy v8
198 new NormalModuleReplacementPlugin(
200 helpers
.root('config/empty.js')
203 new NormalModuleReplacementPlugin(
204 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
205 helpers
.root('config/empty.js')
208 new HashedModuleIdsPlugin(),
211 * Plugin: IgnorePlugin
212 * Description: Don’t generate modules for requests matching the provided RegExp.
214 * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin
217 // new IgnorePlugin(/angular2-hmr/),
220 * Plugin: CompressionPlugin
221 * Description: Prepares compressed versions of assets to serve
222 * them with Content-Encoding
224 * See: https://github.com/webpack/compression-webpack-plugin
226 // install compression-webpack-plugin
227 // new CompressionPlugin({
228 // regExp: /\.css$|\.html$|\.js$|\.map$/,
229 // threshold: 2 * 1024
233 * Plugin LoaderOptionsPlugin (experimental)
235 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
237 new LoaderOptionsPlugin({
243 * Static analysis linter for TypeScript advanced options configuration
244 * Description: An extensible linter for the TypeScript language.
246 * See: https://github.com/wbuchwalter/tslint-loader
255 * Html loader advanced options
257 * See: https://github.com/webpack/html-loader#advanced-options
259 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
262 removeAttributeQuotes: false,
264 customAttrSurround: [
269 customAttrAssign: [/\)?]?=/]
273 // https://github.com/bholloway/resolve-url-loader/issues/36
274 // https://github.com/jtangelder/sass-loader/issues/289
277 path: helpers
.root('dist')
284 * Include polyfills or mocks for various node stuff
285 * Description: Node configuration
287 * See: https://webpack.github.io/docs/configuration.html#node
295 clearImmediate: false,