]>
Commit | Line | Data |
---|---|---|
b20b5fed C |
1 | /** |
2 | * @author: @AngularClass | |
3 | */ | |
4 | ||
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 | ||
9 | /** | |
10 | * Webpack Plugins | |
11 | */ | |
ab32b0fc | 12 | // const ProvidePlugin = require('webpack/lib/ProvidePlugin') |
b20b5fed | 13 | const DefinePlugin = require('webpack/lib/DefinePlugin') |
ab32b0fc | 14 | const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin') |
4d19d2f1 | 15 | const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin') |
ab32b0fc C |
16 | // const IgnorePlugin = require('webpack/lib/IgnorePlugin') |
17 | // const DedupePlugin = require('webpack/lib/optimize/DedupePlugin') | |
b20b5fed | 18 | const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin') |
b20b5fed C |
19 | const WebpackMd5Hash = require('webpack-md5-hash') |
20 | ||
21 | /** | |
22 | * Webpack Constants | |
23 | */ | |
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 | |
2e92c10b | 27 | const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, { |
b20b5fed C |
28 | host: HOST, |
29 | port: PORT, | |
30 | ENV: ENV, | |
31 | HMR: false | |
32 | }) | |
33 | ||
ad22074a C |
34 | module.exports = function (env) { |
35 | return webpackMerge(commonConfig({env: ENV}), { | |
b20b5fed | 36 | /** |
4d19d2f1 C |
37 | * Developer tool to enhance debugging |
38 | * | |
39 | * See: http://webpack.github.io/docs/configuration.html#devtool | |
40 | * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps | |
41 | */ | |
ad22074a | 42 | devtool: 'source-map', |
b20b5fed C |
43 | |
44 | /** | |
4d19d2f1 C |
45 | * Options affecting the output of the compilation. |
46 | * | |
47 | * See: http://webpack.github.io/docs/configuration.html#output | |
48 | */ | |
ad22074a | 49 | output: { |
4d19d2f1 | 50 | |
ad22074a | 51 | /** |
4d19d2f1 C |
52 | * The output directory as absolute path (required). |
53 | * | |
54 | * See: http://webpack.github.io/docs/configuration.html#output-path | |
55 | */ | |
ad22074a C |
56 | path: helpers.root('dist'), |
57 | ||
58 | /** | |
4d19d2f1 C |
59 | * Specifies the name of each output file on disk. |
60 | * IMPORTANT: You must not specify an absolute path here! | |
61 | * | |
62 | * See: http://webpack.github.io/docs/configuration.html#output-filename | |
63 | */ | |
ad22074a C |
64 | filename: '[name].[chunkhash].bundle.js', |
65 | ||
66 | /** | |
4d19d2f1 C |
67 | * The filename of the SourceMaps for the JavaScript files. |
68 | * They are inside the output.path directory. | |
69 | * | |
70 | * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename | |
71 | */ | |
ad22074a C |
72 | sourceMapFilename: '[name].[chunkhash].bundle.map', |
73 | ||
74 | /** | |
4d19d2f1 C |
75 | * The filename of non-entry chunks as relative path |
76 | * inside the output.path directory. | |
77 | * | |
78 | * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename | |
79 | */ | |
80 | chunkFilename: '[id].[chunkhash].chunk.js', | |
ad22074a | 81 | |
4d19d2f1 | 82 | publicPath: '/client/' |
ad22074a C |
83 | }, |
84 | ||
85 | externals: { | |
86 | webtorrent: 'WebTorrent' | |
87 | }, | |
b20b5fed C |
88 | |
89 | /** | |
ad22074a | 90 | * Add additional plugins to the compiler. |
b20b5fed | 91 | * |
ad22074a | 92 | * See: http://webpack.github.io/docs/configuration.html#plugins |
b20b5fed | 93 | */ |
ad22074a C |
94 | plugins: [ |
95 | ||
96 | /** | |
97 | * Plugin: WebpackMd5Hash | |
98 | * Description: Plugin to replace a standard webpack chunkhash with md5. | |
99 | * | |
100 | * See: https://www.npmjs.com/package/webpack-md5-hash | |
101 | */ | |
102 | new WebpackMd5Hash(), | |
103 | ||
104 | /** | |
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. | |
108 | * | |
109 | * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin | |
110 | * See: https://github.com/webpack/docs/wiki/optimization#deduplication | |
111 | */ | |
112 | // new DedupePlugin(), | |
113 | ||
114 | /** | |
115 | * Plugin: DefinePlugin | |
116 | * Description: Define free variables. | |
117 | * Useful for having development builds with debug logging or adding global constants. | |
118 | * | |
119 | * Environment helpers | |
120 | * | |
121 | * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin | |
122 | */ | |
123 | // NOTE: when adding more properties make sure you include them in custom-typings.d.ts | |
124 | new DefinePlugin({ | |
125 | 'ENV': JSON.stringify(METADATA.ENV), | |
126 | 'HMR': METADATA.HMR, | |
127 | 'process.env': { | |
128 | 'ENV': JSON.stringify(METADATA.ENV), | |
129 | 'NODE_ENV': JSON.stringify(METADATA.ENV), | |
130 | 'HMR': METADATA.HMR | |
131 | } | |
132 | }), | |
4d19d2f1 C |
133 | /** |
134 | * Plugin: UglifyJsPlugin | |
135 | * Description: Minimize all JavaScript output of chunks. | |
136 | * Loaders are switched into minimizing mode. | |
137 | * | |
138 | * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin | |
139 | */ | |
ad22074a C |
140 | // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines |
141 | new UglifyJsPlugin({ | |
142 | // beautify: true, //debug | |
143 | // mangle: false, //debug | |
144 | // dead_code: false, //debug | |
145 | // unused: false, //debug | |
146 | // deadCode: false, //debug | |
147 | // compress: { | |
148 | // screw_ie8: true, | |
149 | // keep_fnames: true, | |
150 | // drop_debugger: false, | |
151 | // dead_code: false, | |
152 | // unused: false | |
153 | // }, // debug | |
154 | // comments: true, //debug | |
155 | ||
156 | beautify: false, // prod | |
4d19d2f1 C |
157 | mangle: { |
158 | screw_ie8: true, | |
159 | keep_fnames: true | |
160 | }, // prod | |
161 | compress: { | |
408c7137 C |
162 | screw_ie8: true, |
163 | warnings: false | |
4d19d2f1 | 164 | }, // prod |
ad22074a C |
165 | comments: false // prod |
166 | }), | |
167 | ||
168 | new NormalModuleReplacementPlugin( | |
169 | /angular2-hmr/, | |
170 | helpers.root('config/modules/angular2-hmr-prod.js') | |
4d19d2f1 | 171 | ), |
ad22074a C |
172 | |
173 | /** | |
4d19d2f1 C |
174 | * Plugin: IgnorePlugin |
175 | * Description: Don’t generate modules for requests matching the provided RegExp. | |
176 | * | |
177 | * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin | |
178 | */ | |
179 | ||
180 | // new IgnorePlugin(/angular2-hmr/), | |
181 | ||
182 | /** | |
183 | * Plugin: CompressionPlugin | |
184 | * Description: Prepares compressed versions of assets to serve | |
185 | * them with Content-Encoding | |
186 | * | |
187 | * See: https://github.com/webpack/compression-webpack-plugin | |
188 | */ | |
189 | // install compression-webpack-plugin | |
ad22074a C |
190 | // new CompressionPlugin({ |
191 | // regExp: /\.css$|\.html$|\.js$|\.map$/, | |
192 | // threshold: 2 * 1024 | |
193 | // }) | |
b20b5fed | 194 | |
4d19d2f1 C |
195 | /** |
196 | * Plugin LoaderOptionsPlugin (experimental) | |
197 | * | |
198 | * See: https://gist.github.com/sokra/27b24881210b56bbaff7 | |
199 | */ | |
200 | new LoaderOptionsPlugin({ | |
201 | debug: false, | |
202 | options: { | |
b20b5fed | 203 | |
4d19d2f1 C |
204 | /** |
205 | * Static analysis linter for TypeScript advanced options configuration | |
206 | * Description: An extensible linter for the TypeScript language. | |
207 | * | |
208 | * See: https://github.com/wbuchwalter/tslint-loader | |
209 | */ | |
210 | tslint: { | |
211 | emitErrors: true, | |
212 | failOnHint: true, | |
213 | resourcePath: 'src' | |
214 | }, | |
b20b5fed | 215 | |
4d19d2f1 C |
216 | /** |
217 | * Html loader advanced options | |
218 | * | |
219 | * See: https://github.com/webpack/html-loader#advanced-options | |
220 | */ | |
221 | // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor | |
222 | htmlLoader: { | |
223 | minimize: true, | |
224 | removeAttributeQuotes: false, | |
225 | caseSensitive: true, | |
226 | customAttrSurround: [ | |
227 | [/#/, /(?:)/], | |
228 | [/\*/, /(?:)/], | |
229 | [/\[?\(?/, /(?:)/] | |
230 | ], | |
437cf8b5 | 231 | customAttrAssign: [/\)?]?=/] |
4d19d2f1 C |
232 | }, |
233 | ||
234 | // FIXME: Remove | |
235 | // https://github.com/bholloway/resolve-url-loader/issues/36 | |
236 | // https://github.com/jtangelder/sass-loader/issues/289 | |
237 | context: __dirname, | |
238 | output: { | |
239 | path: helpers.root('dist') | |
240 | } | |
241 | } | |
242 | }) | |
243 | ], | |
ad22074a C |
244 | |
245 | /* | |
4d19d2f1 C |
246 | * Include polyfills or mocks for various node stuff |
247 | * Description: Node configuration | |
248 | * | |
249 | * See: https://webpack.github.io/docs/configuration.html#node | |
250 | */ | |
ad22074a | 251 | node: { |
4d19d2f1 | 252 | global: true, |
ad22074a C |
253 | crypto: 'empty', |
254 | process: false, | |
255 | module: false, | |
256 | clearImmediate: false, | |
257 | setImmediate: false | |
258 | } | |
259 | ||
260 | }) | |
261 | } |