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 ProvidePlugin = require('webpack/lib/ProvidePlugin')
13 const DefinePlugin = require('webpack/lib/DefinePlugin')
14 const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
15 // const IgnorePlugin = require('webpack/lib/IgnorePlugin')
16 // const DedupePlugin = require('webpack/lib/optimize/DedupePlugin')
17 const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin')
18 const WebpackMd5Hash = require('webpack-md5-hash')
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, {
33 module.exports = function (env) {
34 return webpackMerge(commonConfig({env: ENV}), {
36 * Switch loaders to debug mode.
38 * See: http://webpack.github.io/docs/configuration.html#debug
43 * Developer tool to enhance debugging
45 * See: http://webpack.github.io/docs/configuration.html#devtool
46 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
48 devtool: 'source-map',
51 * Options affecting the output of the compilation.
53 * See: http://webpack.github.io/docs/configuration.html#output
57 * The output directory as absolute path (required).
59 * See: http://webpack.github.io/docs/configuration.html#output-path
61 path: helpers.root('dist'),
64 * Specifies the name of each output file on disk.
65 * IMPORTANT: You must not specify an absolute path here!
67 * See: http://webpack.github.io/docs/configuration.html#output-filename
69 filename: '[name].[chunkhash].bundle.js',
72 * The filename of the SourceMaps for the JavaScript files.
73 * They are inside the output.path directory.
75 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
77 sourceMapFilename: '[name].[chunkhash].bundle.map',
80 * The filename of non-entry chunks as relative path
81 * inside the output.path directory.
83 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
85 chunkFilename: '[id].[chunkhash].chunk.js'
90 webtorrent: 'WebTorrent'
94 * Add additional plugins to the compiler.
96 * See: http://webpack.github.io/docs/configuration.html#plugins
101 * Plugin: WebpackMd5Hash
102 * Description: Plugin to replace a standard webpack chunkhash with md5.
104 * See: https://www.npmjs.com/package/webpack-md5-hash
106 new WebpackMd5Hash(),
109 * Plugin: DedupePlugin
110 * Description: Prevents the inclusion of duplicate code into your bundle
111 * and instead applies a copy of the function at runtime.
113 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
114 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
116 // new DedupePlugin(),
119 * Plugin: DefinePlugin
120 * Description: Define free variables.
121 * Useful for having development builds with debug logging or adding global constants.
123 * Environment helpers
125 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
127 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
129 'ENV': JSON.stringify(METADATA.ENV),
132 'ENV': JSON.stringify(METADATA.ENV),
133 'NODE_ENV': JSON.stringify(METADATA.ENV),
139 * Plugin: UglifyJsPlugin
140 * Description: Minimize all JavaScript output of chunks.
141 * Loaders are switched into minimizing mode.
143 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
145 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
147 // beautify: true, //debug
148 // mangle: false, //debug
149 // dead_code: false, //debug
150 // unused: false, //debug
151 // deadCode: false, //debug
154 // keep_fnames: true,
155 // drop_debugger: false,
159 // comments: true, //debug
161 beautify: false, // prod
162 mangle: { screw_ie8: true, keep_fnames: true }, // prod
163 compress: { screw_ie8: true }, // prod
164 comments: false // prod
167 new NormalModuleReplacementPlugin(
169 helpers.root('config/modules/angular2-hmr-prod.js')
173 * Plugin: CompressionPlugin
174 * Description: Prepares compressed versions of assets to serve
175 * them with Content-Encoding
177 * See: https://github.com/webpack/compression-webpack-plugin
179 // new CompressionPlugin({
180 // regExp: /\.css$|\.html$|\.js$|\.map$/,
181 // threshold: 2 * 1024
187 * Static analysis linter for TypeScript advanced options configuration
188 * Description: An extensible linter for the TypeScript language.
190 * See: https://github.com/wbuchwalter/tslint-loader
199 * Html loader advanced options
201 * See: https://github.com/webpack/html-loader#advanced-options
203 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
206 removeAttributeQuotes: false,
208 customAttrSurround: [
213 customAttrAssign: [/\)?\]?=/]
217 * Include polyfills or mocks for various node stuff
218 * Description: Node configuration
220 * See: https://webpack.github.io/docs/configuration.html#node
227 clearImmediate: false,