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 LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
16 // const IgnorePlugin = require('webpack/lib/IgnorePlugin')
17 // const DedupePlugin = require('webpack/lib/optimize/DedupePlugin')
18 const UglifyJsPlugin
= require('webpack/lib/optimize/UglifyJsPlugin')
19 const WebpackMd5Hash
= require('webpack-md5-hash')
24 const ENV
= process
.env
.NODE_ENV
= process
.env
.ENV
= 'production'
25 const HOST
= process
.env
.HOST
|| 'localhost'
26 const PORT
= process
.env
.PORT
|| 8080
27 const METADATA
= webpackMerge(commonConfig({env: ENV
}).metadata
, {
34 module
.exports = function (env
) {
35 return webpackMerge(commonConfig({env: ENV
}), {
37 * Developer tool to enhance debugging
39 * See: http://webpack.github.io/docs/configuration.html#devtool
40 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
42 devtool: 'source-map',
45 * Options affecting the output of the compilation.
47 * See: http://webpack.github.io/docs/configuration.html#output
52 * The output directory as absolute path (required).
54 * See: http://webpack.github.io/docs/configuration.html#output-path
56 path: helpers
.root('dist'),
59 * Specifies the name of each output file on disk.
60 * IMPORTANT: You must not specify an absolute path here!
62 * See: http://webpack.github.io/docs/configuration.html#output-filename
64 filename: '[name].[chunkhash].bundle.js',
67 * The filename of the SourceMaps for the JavaScript files.
68 * They are inside the output.path directory.
70 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
72 sourceMapFilename: '[name].[chunkhash].bundle.map',
75 * The filename of non-entry chunks as relative path
76 * inside the output.path directory.
78 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
80 chunkFilename: '[id].[chunkhash].chunk.js',
82 publicPath: '/client/'
86 webtorrent: 'WebTorrent'
90 * Add additional plugins to the compiler.
92 * See: http://webpack.github.io/docs/configuration.html#plugins
97 * Plugin: WebpackMd5Hash
98 * Description: Plugin to replace a standard webpack chunkhash with md5.
100 * See: https://www.npmjs.com/package/webpack-md5-hash
102 new WebpackMd5Hash(),
105 * Plugin: DedupePlugin
106 * Description: Prevents the inclusion of duplicate code into your bundle
107 * and instead applies a copy of the function at runtime.
109 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
110 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
112 // new DedupePlugin(),
115 * Plugin: DefinePlugin
116 * Description: Define free variables.
117 * Useful for having development builds with debug logging or adding global constants.
119 * Environment helpers
121 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
123 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
125 'ENV': JSON
.stringify(METADATA
.ENV
),
128 'ENV': JSON
.stringify(METADATA
.ENV
),
129 'NODE_ENV': JSON
.stringify(METADATA
.ENV
),
134 * Plugin: UglifyJsPlugin
135 * Description: Minimize all JavaScript output of chunks.
136 * Loaders are switched into minimizing mode.
138 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
140 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
142 // beautify: true, //debug
143 // mangle: false, //debug
144 // dead_code: false, //debug
145 // unused: false, //debug
146 // deadCode: false, //debug
149 // keep_fnames: true,
150 // drop_debugger: false,
154 // comments: true, //debug
156 beautify: false, // prod
165 comments: false // prod
168 new NormalModuleReplacementPlugin(
170 helpers
.root('config/modules/angular2-hmr-prod.js')
174 * Plugin: IgnorePlugin
175 * Description: Don’t generate modules for requests matching the provided RegExp.
177 * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin
180 // new IgnorePlugin(/angular2-hmr/),
183 * Plugin: CompressionPlugin
184 * Description: Prepares compressed versions of assets to serve
185 * them with Content-Encoding
187 * See: https://github.com/webpack/compression-webpack-plugin
189 // install compression-webpack-plugin
190 // new CompressionPlugin({
191 // regExp: /\.css$|\.html$|\.js$|\.map$/,
192 // threshold: 2 * 1024
196 * Plugin LoaderOptionsPlugin (experimental)
198 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
200 new LoaderOptionsPlugin({
205 * Static analysis linter for TypeScript advanced options configuration
206 * Description: An extensible linter for the TypeScript language.
208 * See: https://github.com/wbuchwalter/tslint-loader
217 * Html loader advanced options
219 * See: https://github.com/webpack/html-loader#advanced-options
221 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
224 removeAttributeQuotes: false,
226 customAttrSurround: [
231 customAttrAssign: [/\)?]?=/]
235 // https://github.com/bholloway/resolve-url-loader/issues/36
236 // https://github.com/jtangelder/sass-loader/issues/289
239 path: helpers
.root('dist')
246 * Include polyfills or mocks for various node stuff
247 * Description: Node configuration
249 * See: https://webpack.github.io/docs/configuration.html#node
256 clearImmediate: false,