Add webtorrent and jquery to webpack
[oweals/peertube.git] / client / config / webpack.prod.js
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  */
12 const DefinePlugin = require('webpack/lib/DefinePlugin')
13 const DedupePlugin = require('webpack/lib/optimize/DedupePlugin')
14 const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin')
15 const CompressionPlugin = require('compression-webpack-plugin')
16 const WebpackMd5Hash = require('webpack-md5-hash')
17
18 /**
19  * Webpack Constants
20  */
21 const ENV = process.env.NODE_ENV = process.env.ENV = 'production'
22 const HOST = process.env.HOST || 'localhost'
23 const PORT = process.env.PORT || 8080
24 const METADATA = webpackMerge(commonConfig.metadata, {
25   host: HOST,
26   port: PORT,
27   ENV: ENV,
28   HMR: false
29 })
30
31 module.exports = webpackMerge(commonConfig, {
32   /**
33    * Switch loaders to debug mode.
34    *
35    * See: http://webpack.github.io/docs/configuration.html#debug
36    */
37   debug: false,
38
39   /**
40    * Developer tool to enhance debugging
41    *
42    * See: http://webpack.github.io/docs/configuration.html#devtool
43    * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
44    */
45   devtool: 'source-map',
46
47   /**
48    * Options affecting the output of the compilation.
49    *
50    * See: http://webpack.github.io/docs/configuration.html#output
51    */
52   output: {
53     /**
54      * The output directory as absolute path (required).
55      *
56      * See: http://webpack.github.io/docs/configuration.html#output-path
57      */
58     path: helpers.root('dist'),
59
60     /**
61      * Specifies the name of each output file on disk.
62      * IMPORTANT: You must not specify an absolute path here!
63      *
64      * See: http://webpack.github.io/docs/configuration.html#output-filename
65      */
66     filename: '[name].[chunkhash].bundle.js',
67
68     /**
69      * The filename of the SourceMaps for the JavaScript files.
70      * They are inside the output.path directory.
71      *
72      * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
73      */
74     sourceMapFilename: '[name].[chunkhash].bundle.map',
75
76     /**
77      * The filename of non-entry chunks as relative path
78      * inside the output.path directory.
79      *
80      * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
81      */
82     chunkFilename: '[id].[chunkhash].chunk.js'
83
84   },
85
86   /**
87    * Add additional plugins to the compiler.
88    *
89    * See: http://webpack.github.io/docs/configuration.html#plugins
90    */
91   plugins: [
92
93     /**
94      * Plugin: WebpackMd5Hash
95      * Description: Plugin to replace a standard webpack chunkhash with md5.
96      *
97      * See: https://www.npmjs.com/package/webpack-md5-hash
98      */
99     new WebpackMd5Hash(),
100
101     /**
102      * Plugin: DedupePlugin
103      * Description: Prevents the inclusion of duplicate code into your bundle
104      * and instead applies a copy of the function at runtime.
105      *
106      * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
107      * See: https://github.com/webpack/docs/wiki/optimization#deduplication
108      */
109     new DedupePlugin(),
110
111     /**
112      * Plugin: DefinePlugin
113      * Description: Define free variables.
114      * Useful for having development builds with debug logging or adding global constants.
115      *
116      * Environment helpers
117      *
118      * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
119      */
120     // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
121     new DefinePlugin({
122       'ENV': JSON.stringify(METADATA.ENV),
123       'HMR': METADATA.HMR,
124       'process.env': {
125         'ENV': JSON.stringify(METADATA.ENV),
126         'NODE_ENV': JSON.stringify(METADATA.ENV),
127         'HMR': METADATA.HMR
128       }
129     }),
130
131     /**
132      * Plugin: UglifyJsPlugin
133      * Description: Minimize all JavaScript output of chunks.
134      * Loaders are switched into minimizing mode.
135      *
136      * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
137      */
138     // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
139     new UglifyJsPlugin({
140       // beautify: true, //debug
141       // mangle: false, //debug
142       // dead_code: false, //debug
143       // unused: false, //debug
144       // deadCode: false, //debug
145       // compress: {
146       //   screw_ie8: true,
147       //   keep_fnames: true,
148       //   drop_debugger: false,
149       //   dead_code: false,
150       //   unused: false
151       // }, // debug
152       // comments: true, //debug
153
154       beautify: false, // prod
155
156       mangle: {
157         screw_ie8: true,
158         keep_fnames: true
159       }, // prod
160
161       compress: {
162         screw_ie8: true
163       }, // prod
164
165       comments: false // prod
166     }),
167
168     /**
169      * Plugin: CompressionPlugin
170      * Description: Prepares compressed versions of assets to serve
171      * them with Content-Encoding
172      *
173      * See: https://github.com/webpack/compression-webpack-plugin
174      */
175     new CompressionPlugin({
176       regExp: /\.css$|\.html$|\.js$|\.map$/,
177       threshold: 2 * 1024
178     })
179
180   ],
181
182   /**
183    * Static analysis linter for TypeScript advanced options configuration
184    * Description: An extensible linter for the TypeScript language.
185    *
186    * See: https://github.com/wbuchwalter/tslint-loader
187    */
188   tslint: {
189     emitErrors: true,
190     failOnHint: true,
191     resourcePath: 'src'
192   },
193
194   /**
195    * Html loader advanced options
196    *
197    * See: https://github.com/webpack/html-loader#advanced-options
198    */
199   // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
200   htmlLoader: {
201     minimize: true,
202     removeAttributeQuotes: false,
203     caseSensitive: true,
204     customAttrSurround: [
205       [/#/, /(?:)/],
206       [/\*/, /(?:)/],
207       [/\[?\(?/, /(?:)/]
208     ],
209     customAttrAssign: [/\)?\]?=/]
210   },
211
212   /*
213    * Include polyfills or mocks for various node stuff
214    * Description: Node configuration
215    *
216    * See: https://webpack.github.io/docs/configuration.html#node
217    */
218   node: {
219     global: 'window',
220     crypto: 'empty',
221     process: false,
222     module: false,
223     clearImmediate: false,
224     setImmediate: false
225   }
226
227 })