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