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 HashedModuleIdsPlugin
= require('webpack/lib/HashedModuleIdsPlugin')
18 const UglifyJsPlugin
= require('uglifyjs-webpack-plugin')
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 AOT
= process
.env
.BUILD_AOT
|| helpers
.hasNpmFlag('aot')
35 module
.exports = function (env
) {
37 videoEmbedConfig({ env: ENV
}),
39 webpackMerge(commonConfig({ env: ENV
}), {
41 * Developer tool to enhance debugging
43 * See: http://webpack.github.io/docs/configuration.html#devtool
44 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
46 devtool: 'source-map',
49 * Options affecting the output of the compilation.
51 * See: http://webpack.github.io/docs/configuration.html#output
56 * The output directory as absolute path (required).
58 * See: http://webpack.github.io/docs/configuration.html#output-path
60 path: helpers
.root('dist'),
63 * Specifies the name of each output file on disk.
64 * IMPORTANT: You must not specify an absolute path here!
66 * See: http://webpack.github.io/docs/configuration.html#output-filename
68 filename: '[name].[chunkhash].bundle.js',
71 * The filename of the SourceMaps for the JavaScript files.
72 * They are inside the output.path directory.
74 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
76 sourceMapFilename: '[file].map',
79 * The filename of non-entry chunks as relative path
80 * inside the output.path directory.
82 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
84 chunkFilename: '[name].[chunkhash].chunk.js',
86 publicPath: '/client/'
92 test: /junk\/index\.js$/,
93 // exclude: /(node_modules|bower_components)/,
95 loader: 'babel-loader',
105 * Add additional plugins to the compiler.
107 * See: http://webpack.github.io/docs/configuration.html#plugins
112 * Webpack plugin to optimize a JavaScript file for faster initial load
113 * by wrapping eagerly-invoked functions.
115 * See: https://github.com/vigneshshanmugam/optimize-js-plugin
118 new OptimizeJsPlugin({
123 * Plugin: DedupePlugin
124 * Description: Prevents the inclusion of duplicate code into your bundle
125 * and instead applies a copy of the function at runtime.
127 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
128 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
130 // new DedupePlugin(),
133 * Plugin: DefinePlugin
134 * Description: Define free variables.
135 * Useful for having development builds with debug logging or adding global constants.
137 * Environment helpers
139 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
141 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
143 'ENV': JSON
.stringify(METADATA
.ENV
),
145 'API_URL': JSON
.stringify(METADATA
.API_URL
),
147 'process.version': JSON
.stringify(process
.version
),
148 'process.env.ENV': JSON
.stringify(METADATA
.ENV
),
149 'process.env.NODE_ENV': JSON
.stringify(METADATA
.ENV
),
150 'process.env.HMR': METADATA
.HMR
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
177 * Plugin: NormalModuleReplacementPlugin
178 * Description: Replace resources that matches resourceRegExp with newResource
180 * See: http://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
182 new NormalModuleReplacementPlugin(
183 /(angular2|@angularclass)((\\|\/)|-)hmr/,
184 helpers
.root('config/empty.js')
187 new NormalModuleReplacementPlugin(
188 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
189 helpers
.root('config/empty.js')
192 new HashedModuleIdsPlugin(),
198 new NormalModuleReplacementPlugin(
199 /@angular(\\|\/)compiler/,
200 helpers
.root('config/empty.js')
202 ) : (new LoaderOptionsPlugin({}))),
205 * Plugin LoaderOptionsPlugin (experimental)
207 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
209 new LoaderOptionsPlugin({
215 * Static analysis linter for TypeScript advanced options configuration
216 * Description: An extensible linter for the TypeScript language.
218 * See: https://github.com/wbuchwalter/tslint-loader
227 * Html loader advanced options
229 * See: https://github.com/webpack/html-loader#advanced-options
231 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
234 removeAttributeQuotes: false,
236 customAttrSurround: [
241 customAttrAssign: [/\)?]?=/]
245 // https://github.com/bholloway/resolve-url-loader/issues/36
246 // https://github.com/jtangelder/sass-loader/issues/289
249 path: helpers
.root('dist')
256 * Include polyfills or mocks for various node stuff
257 * Description: Node configuration
259 * See: https://webpack.github.io/docs/configuration.html#node
267 clearImmediate: false,