Client: add webpack notifier
[oweals/peertube.git] / client / config / webpack.common.js
1 const webpack = require('webpack')
2 const helpers = require('./helpers')
3
4 /*
5  * Webpack Plugins
6  */
7
8 var CopyWebpackPlugin = (CopyWebpackPlugin = require('copy-webpack-plugin'), CopyWebpackPlugin.default || CopyWebpackPlugin)
9 const HtmlWebpackPlugin = require('html-webpack-plugin')
10 const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin
11 const WebpackNotifierPlugin = require('webpack-notifier')
12
13 /*
14  * Webpack Constants
15  */
16 const METADATA = {
17   title: 'PeerTube',
18   baseUrl: '/'
19 }
20
21 /*
22  * Webpack configuration
23  *
24  * See: http://webpack.github.io/docs/configuration.html#cli
25  */
26 module.exports = {
27   /*
28    * Static metadata for index.html
29    *
30    * See: (custom attribute)
31    */
32   metadata: METADATA,
33
34   /*
35    * Cache generated modules and chunks to improve performance for multiple incremental builds.
36    * This is enabled by default in watch mode.
37    * You can pass false to disable it.
38    *
39    * See: http://webpack.github.io/docs/configuration.html#cache
40    */
41   // cache: false,
42
43   /*
44    * The entry point for the bundle
45    * Our Angular.js app
46    *
47    * See: http://webpack.github.io/docs/configuration.html#entry
48    */
49   entry: {
50     'polyfills': './src/polyfills.ts',
51     'vendor': './src/vendor.ts',
52     'main': './src/main.ts'
53   },
54
55   /*
56    * Options affecting the resolving of modules.
57    *
58    * See: http://webpack.github.io/docs/configuration.html#resolve
59    */
60   resolve: {
61     /*
62      * An array of extensions that should be used to resolve modules.
63      *
64      * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
65      */
66     extensions: [ '', '.ts', '.js', '.scss' ],
67
68     // Make sure root is src
69     root: helpers.root('src'),
70
71     // remove other default values
72     modulesDirectories: [ 'node_modules' ],
73
74     packageAlias: 'browser'
75
76   },
77
78   output: {
79     publicPath: '/client/'
80   },
81
82   /*
83    * Options affecting the normal modules.
84    *
85    * See: http://webpack.github.io/docs/configuration.html#module
86    */
87   module: {
88     /*
89      * An array of applied pre and post loaders.
90      *
91      * See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
92      */
93     preLoaders: [
94
95       /*
96        * Tslint loader support for *.ts files
97        *
98        * See: https://github.com/wbuchwalter/tslint-loader
99        */
100       // { test: /\.ts$/, loader: 'tslint-loader', exclude: [ helpers.root('node_modules') ] },
101
102       /*
103        * Source map loader support for *.js files
104        * Extracts SourceMaps for source files that as added as sourceMappingURL comment.
105        *
106        * See: https://github.com/webpack/source-map-loader
107        */
108       {
109         test: /\.js$/,
110         loader: 'source-map-loader',
111         exclude: [
112           // these packages have problems with their sourcemaps
113           helpers.root('node_modules/rxjs'),
114           helpers.root('node_modules/@angular')
115         ]
116       }
117
118     ],
119
120     /*
121      * An array of automatically applied loaders.
122      *
123      * IMPORTANT: The loaders here are resolved relative to the resource which they are applied to.
124      * This means they are not resolved relative to the configuration file.
125      *
126      * See: http://webpack.github.io/docs/configuration.html#module-loaders
127      */
128     loaders: [
129
130       /*
131        * Typescript loader support for .ts and Angular 2 async routes via .async.ts
132        *
133        * See: https://github.com/s-panferov/awesome-typescript-loader
134        */
135       {
136         test: /\.ts$/,
137         loader: 'awesome-typescript-loader',
138         exclude: [/\.(spec|e2e)\.ts$/]
139       },
140
141       /*
142        * Json loader support for *.json files.
143        *
144        * See: https://github.com/webpack/json-loader
145        */
146       {
147         test: /\.json$/,
148         loader: 'json-loader'
149       },
150
151       {
152         test: /\.scss$/,
153         exclude: /node_modules/,
154         loaders: [ 'raw-loader', 'sass-loader' ]
155       },
156
157       {
158         test: /\.(woff2?|ttf|eot|svg)$/,
159         loader: 'url?limit=10000&name=assets/fonts/[hash].[ext]'
160       },
161
162       /* Raw loader support for *.html
163        * Returns file content as string
164        *
165        * See: https://github.com/webpack/raw-loader
166        */
167       {
168         test: /\.html$/,
169         loader: 'raw-loader',
170         exclude: [ helpers.root('src/index.html') ]
171       }
172
173     ]
174
175   },
176
177   sassLoader: {
178     precision: 10
179   },
180
181   /*
182    * Add additional plugins to the compiler.
183    *
184    * See: http://webpack.github.io/docs/configuration.html#plugins
185    */
186   plugins: [
187
188     /*
189      * Plugin: ForkCheckerPlugin
190      * Description: Do type checking in a separate process, so webpack don't need to wait.
191      *
192      * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
193      */
194     new ForkCheckerPlugin(),
195
196     /*
197      * Plugin: OccurenceOrderPlugin
198      * Description: Varies the distribution of the ids to get the smallest id length
199      * for often used ids.
200      *
201      * See: https://webpack.github.io/docs/list-of-plugins.html#occurrenceorderplugin
202      * See: https://github.com/webpack/docs/wiki/optimization#minimize
203      */
204     new webpack.optimize.OccurenceOrderPlugin(true),
205
206     /*
207      * Plugin: CommonsChunkPlugin
208      * Description: Shares common code between the pages.
209      * It identifies common modules and put them into a commons chunk.
210      *
211      * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
212      * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
213      */
214     new webpack.optimize.CommonsChunkPlugin({
215       name: [ 'polyfills', 'vendor' ].reverse()
216     }),
217
218     /*
219      * Plugin: CopyWebpackPlugin
220      * Description: Copy files and directories in webpack.
221      *
222      * Copies project static assets.
223      *
224      * See: https://www.npmjs.com/package/copy-webpack-plugin
225      */
226     new CopyWebpackPlugin([
227       {
228         from: 'src/assets',
229         to: 'assets'
230       },
231       {
232         from: 'node_modules/webtorrent/webtorrent.min.js',
233         to: 'assets/webtorrent'
234       }
235     ]),
236
237     /*
238      * Plugin: HtmlWebpackPlugin
239      * Description: Simplifies creation of HTML files to serve your webpack bundles.
240      * This is especially useful for webpack bundles that include a hash in the filename
241      * which changes every compilation.
242      *
243      * See: https://github.com/ampedandwired/html-webpack-plugin
244      */
245     new HtmlWebpackPlugin({
246       template: 'src/index.html',
247       chunksSortMode: 'dependency'
248     }),
249
250     new WebpackNotifierPlugin({ alwaysNotify: true })
251   ],
252
253   /*
254    * Include polyfills or mocks for various node stuff
255    * Description: Node configuration
256    *
257    * See: https://webpack.github.io/docs/configuration.html#node
258    */
259   node: {
260     global: 'window',
261     crypto: 'empty',
262     fs: 'empty',
263     events: true,
264     module: false,
265     clearImmediate: false,
266     setImmediate: false
267   }
268
269 }