]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/config/webpack.prod.js
Upgrade client dependencies
[github/Chocobozzz/PeerTube.git] / client / config / webpack.prod.js
... / ...
CommitLineData
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
8const videoEmbedConfig = require('./webpack.video-embed.js')
9
10/**
11 * Webpack Plugins
12 */
13const DefinePlugin = require('webpack/lib/DefinePlugin')
14const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
15const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
16const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
17const OptimizeJsPlugin = require('optimize-js-plugin')
18const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin')
19const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
20const ExtractTextPlugin = require('extract-text-webpack-plugin')
21
22/**
23 * Webpack Constants
24 */
25const ENV = process.env.NODE_ENV = process.env.ENV = 'production'
26const HOST = process.env.HOST || 'localhost'
27const PORT = process.env.PORT || 8080
28const AOT = process.env.BUILD_AOT || helpers.hasNpmFlag('aot')
29const METADATA = {
30 host: HOST,
31 port: PORT,
32 ENV: ENV,
33 HMR: false,
34 AOT: AOT,
35 API_URL: ''
36}
37
38module.exports = function (env) {
39 return [
40 videoEmbedConfig({ env: ENV }),
41
42 webpackMerge(commonConfig({ env: ENV }), {
43 /**
44 * Developer tool to enhance debugging
45 *
46 * See: http://webpack.github.io/docs/configuration.html#devtool
47 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
48 */
49 devtool: 'source-map',
50
51 /**
52 * Options affecting the output of the compilation.
53 *
54 * See: http://webpack.github.io/docs/configuration.html#output
55 */
56 output: {
57
58 /**
59 * The output directory as absolute path (required).
60 *
61 * See: http://webpack.github.io/docs/configuration.html#output-path
62 */
63 path: helpers.root('dist'),
64
65 /**
66 * Specifies the name of each output file on disk.
67 * IMPORTANT: You must not specify an absolute path here!
68 *
69 * See: http://webpack.github.io/docs/configuration.html#output-filename
70 */
71 filename: '[name].[chunkhash].bundle.js',
72
73 /**
74 * The filename of the SourceMaps for the JavaScript files.
75 * They are inside the output.path directory.
76 *
77 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
78 */
79 sourceMapFilename: '[file].map',
80
81 /**
82 * The filename of non-entry chunks as relative path
83 * inside the output.path directory.
84 *
85 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
86 */
87 chunkFilename: '[name].[chunkhash].chunk.js',
88
89 publicPath: '/client/'
90 },
91
92 module: {
93 rules: [
94 {
95 test: /junk\/index\.js$/,
96 // exclude: /(node_modules|bower_components)/,
97 use: {
98 loader: 'babel-loader',
99 options: {
100 presets: [ 'env' ]
101 }
102 }
103 }
104 ]
105 },
106
107 /**
108 * Add additional plugins to the compiler.
109 *
110 * See: http://webpack.github.io/docs/configuration.html#plugins
111 */
112 plugins: [
113
114 /**
115 * Webpack plugin to optimize a JavaScript file for faster initial load
116 * by wrapping eagerly-invoked functions.
117 *
118 * See: https://github.com/vigneshshanmugam/optimize-js-plugin
119 */
120
121 new OptimizeJsPlugin({
122 sourceMap: false
123 }),
124
125 new ExtractTextPlugin({
126 filename: '[name].[contenthash].css',
127 allChunks: true
128 }),
129
130 /**
131 * Plugin: DefinePlugin
132 * Description: Define free variables.
133 * Useful for having development builds with debug logging or adding global constants.
134 *
135 * Environment helpers
136 *
137 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
138 */
139 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
140 new DefinePlugin({
141 'ENV': JSON.stringify(METADATA.ENV),
142 'HMR': METADATA.HMR,
143 'API_URL': JSON.stringify(METADATA.API_URL),
144 'AOT': METADATA.AOT,
145 'process.version': JSON.stringify(process.version),
146 'process.env.ENV': JSON.stringify(METADATA.ENV),
147 'process.env.NODE_ENV': JSON.stringify(METADATA.ENV),
148 'process.env.HMR': METADATA.HMR
149 }),
150
151 /**
152 * Plugin: UglifyJsPlugin
153 * Description: Minimize all JavaScript output of chunks.
154 * Loaders are switched into minimizing mode.
155 *
156 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
157 */
158 new UglifyJsPlugin({
159 parallel: true,
160 uglifyOptions: {
161 ie8: false,
162 ecma: 6,
163 warnings: true,
164 mangle: true,
165 output: {
166 comments: false,
167 beautify: false
168 }
169 },
170 warnings: true
171 }),
172
173 /**
174 * Plugin: NormalModuleReplacementPlugin
175 * Description: Replace resources that matches resourceRegExp with newResource
176 *
177 * See: http://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
178 */
179 new NormalModuleReplacementPlugin(
180 /(angular2|@angularclass)((\\|\/)|-)hmr/,
181 helpers.root('config/empty.js')
182 ),
183
184 new NormalModuleReplacementPlugin(
185 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
186 helpers.root('config/empty.js')
187 ),
188
189 new HashedModuleIdsPlugin(),
190
191 /**
192 * AoT
193 */
194 (AOT ? (
195 new NormalModuleReplacementPlugin(
196 /@angular(\\|\/)compiler/,
197 helpers.root('config/empty.js')
198 )
199 ) : (new LoaderOptionsPlugin({}))),
200
201 /**
202 * Plugin LoaderOptionsPlugin (experimental)
203 *
204 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
205 */
206 new LoaderOptionsPlugin({
207 minimize: true,
208 debug: false,
209 options: {
210
211 /**
212 * Static analysis linter for TypeScript advanced options configuration
213 * Description: An extensible linter for the TypeScript language.
214 *
215 * See: https://github.com/wbuchwalter/tslint-loader
216 */
217 tslint: {
218 emitErrors: true,
219 failOnHint: true,
220 resourcePath: 'src'
221 },
222
223 /**
224 * Html loader advanced options
225 *
226 * See: https://github.com/webpack/html-loader#advanced-options
227 */
228 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
229 htmlLoader: {
230 minimize: true,
231 removeAttributeQuotes: false,
232 caseSensitive: true,
233 customAttrSurround: [
234 [/#/, /(?:)/],
235 [/\*/, /(?:)/],
236 [/\[?\(?/, /(?:)/]
237 ],
238 customAttrAssign: [/\)?]?=/]
239 },
240
241 // FIXME: Remove
242 // https://github.com/bholloway/resolve-url-loader/issues/36
243 // https://github.com/jtangelder/sass-loader/issues/289
244 context: __dirname,
245 output: {
246 path: helpers.root('dist')
247 }
248 }
249 }),
250
251 new BundleAnalyzerPlugin({
252 // Can be `server`, `static` or `disabled`.
253 // In `server` mode analyzer will start HTTP server to show bundle report.
254 // In `static` mode single HTML file with bundle report will be generated.
255 // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
256 analyzerMode: 'static',
257 // Path to bundle report file that will be generated in `static` mode.
258 // Relative to bundles output directory.
259 reportFilename: 'report.html',
260 // Automatically open report in default browser
261 openAnalyzer: false,
262 // If `true`, Webpack Stats JSON file will be generated in bundles output directory
263 generateStatsFile: true,
264 // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
265 // Relative to bundles output directory.
266 statsFilename: 'stats.json',
267 // Options for `stats.toJson()` method.
268 // For example you can exclude sources of your modules from stats file with `source: false` option.
269 // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
270 statsOptions: null,
271 // Log level. Can be 'info', 'warn', 'error' or 'silent'.
272 logLevel: 'info'
273 })
274 ],
275
276 /*
277 * Include polyfills or mocks for various node stuff
278 * Description: Node configuration
279 *
280 * See: https://webpack.github.io/docs/configuration.html#node
281 */
282 node: {
283 global: true,
284 crypto: 'empty',
285 fs: 'empty',
286 process: true,
287 module: false,
288 clearImmediate: false,
289 setImmediate: false
290 }
291
292 })
293 ]
294}