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