]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/config/webpack.common.js
Client: responsive design
[github/Chocobozzz/PeerTube.git] / client / config / webpack.common.js
CommitLineData
4a6995be
C
1const helpers = require('./helpers')
2
3/*
4 * Webpack Plugins
5 */
6
2e92c10b 7const AssetsPlugin = require('assets-webpack-plugin')
b99290b1 8const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
d268c551 9const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
c16ce1de
C
10const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin')
11const CopyWebpackPlugin = require('copy-webpack-plugin')
12const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
13const HtmlWebpackPlugin = require('html-webpack-plugin')
4d19d2f1
C
14const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
15const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
c16ce1de
C
16const ngcWebpack = require('ngc-webpack')
17
66698b83 18const WebpackNotifierPlugin = require('webpack-notifier')
4a6995be
C
19
20/*
21 * Webpack Constants
22 */
23const METADATA = {
24 title: 'PeerTube',
ab32b0fc
C
25 baseUrl: '/',
26 isDevServer: helpers.isWebpackDevServer()
4a6995be
C
27}
28
29/*
30 * Webpack configuration
31 *
32 * See: http://webpack.github.io/docs/configuration.html#cli
33 */
2e92c10b 34module.exports = function (options) {
c16ce1de
C
35 const isProd = options.env === 'production'
36 const AOT = isProd
2e92c10b
C
37
38 return {
4a6995be 39
2e92c10b
C
40 /*
41 * Cache generated modules and chunks to improve performance for multiple incremental builds.
42 * This is enabled by default in watch mode.
43 * You can pass false to disable it.
44 *
45 * See: http://webpack.github.io/docs/configuration.html#cache
46 */
47 // cache: false,
4a6995be 48
2e92c10b
C
49 /*
50 * The entry point for the bundle
51 * Our Angular.js app
52 *
53 * See: http://webpack.github.io/docs/configuration.html#entry
54 */
55 entry: {
c16ce1de
C
56 'polyfills': './src/polyfills.browser.ts',
57 'main': AOT
58 ? './src/main.browser.aot.ts'
59 : './src/main.browser.ts'
2e92c10b 60 },
b20b5fed 61
4a6995be 62 /*
2e92c10b 63 * Options affecting the resolving of modules.
4a6995be 64 *
2e92c10b 65 * See: http://webpack.github.io/docs/configuration.html#resolve
4a6995be 66 */
2e92c10b
C
67 resolve: {
68 /*
69 * An array of extensions that should be used to resolve modules.
70 *
71 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
72 */
4d19d2f1 73 extensions: [ '.ts', '.js', '.json', '.scss' ],
2e92c10b 74
240c64c5 75 modules: [ helpers.root('src'), helpers.root('node_modules') ]
2e92c10b 76 },
4a6995be
C
77
78 /*
2e92c10b 79 * Options affecting the normal modules.
4a6995be 80 *
2e92c10b 81 * See: http://webpack.github.io/docs/configuration.html#module
4a6995be 82 */
2e92c10b 83 module: {
4a6995be 84
4d19d2f1 85 rules: [
4a6995be 86
2e92c10b
C
87 /*
88 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
89 *
90 * See: https://github.com/s-panferov/awesome-typescript-loader
91 */
92 {
93 test: /\.ts$/,
c16ce1de 94 use: [
2e92c10b 95 '@angularclass/hmr-loader?pretty=' + !isProd + '&prod=' + isProd,
c16ce1de
C
96 'awesome-typescript-loader?{configFileName: "tsconfig.webpack.json"}',
97 'angular2-template-loader',
98 {
99 loader: 'ng-router-loader',
100 options: {
101 loader: 'async-system',
102 genDir: 'compiled',
103 aot: AOT
104 }
105 }
2e92c10b
C
106 ],
107 exclude: [/\.(spec|e2e)\.ts$/]
108 },
4a6995be 109
2e92c10b
C
110 /*
111 * Json loader support for *.json files.
112 *
113 * See: https://github.com/webpack/json-loader
114 */
115 {
116 test: /\.json$/,
117 loader: 'json-loader'
118 },
4a6995be 119
2e92c10b 120 {
ad22074a 121 test: /\.(sass|scss)$/,
383bfc83
C
122 use: [
123 'css-to-string-loader',
124 'css-loader?sourceMap',
125 'resolve-url-loader',
126 {
127 loader: 'sass-loader',
128 options: {
129 sourceMap: true
130 }
131 },
132 {
133 loader: 'sass-resources-loader',
134 options: {
135 resources: [
136 helpers.root('src/sass/_variables.scss')
137 ]
138 }
139 }
140 ]
2e92c10b 141 },
c16ce1de
C
142 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
143 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
4a6995be 144
2e92c10b
C
145 /* Raw loader support for *.html
146 * Returns file content as string
147 *
148 * See: https://github.com/webpack/raw-loader
149 */
150 {
151 test: /\.html$/,
152 loader: 'raw-loader',
383bfc83
C
153 exclude: [
154 helpers.root('src/index.html'),
155 helpers.root('src/standalone/videos/embed.html')
156 ]
2e92c10b 157 }
4a6995be 158
2e92c10b
C
159 ]
160
161 },
162
4a6995be 163 /*
2e92c10b 164 * Add additional plugins to the compiler.
4a6995be 165 *
2e92c10b 166 * See: http://webpack.github.io/docs/configuration.html#plugins
4a6995be 167 */
2e92c10b
C
168 plugins: [
169 new AssetsPlugin({
170 path: helpers.root('dist'),
171 filename: 'webpack-assets.json',
172 prettyPrint: true
173 }),
174
175 /*
176 * Plugin: ForkCheckerPlugin
177 * Description: Do type checking in a separate process, so webpack don't need to wait.
178 *
179 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
180 */
c16ce1de 181 new CheckerPlugin(),
2e92c10b
C
182
183 /*
184 * Plugin: CommonsChunkPlugin
185 * Description: Shares common code between the pages.
186 * It identifies common modules and put them into a commons chunk.
187 *
188 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
189 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
190 */
c16ce1de
C
191 new CommonsChunkPlugin({
192 name: 'polyfills',
193 chunks: ['polyfills']
194 }),
195
196 // This enables tree shaking of the vendor modules
197 new CommonsChunkPlugin({
198 name: 'vendor',
199 chunks: ['main'],
200 minChunks: module => /node_modules\//.test(module.resource)
201 }),
202
203 // Specify the correct order the scripts will be injected in
204 new CommonsChunkPlugin({
205 name: ['polyfills', 'vendor'].reverse()
2e92c10b
C
206 }),
207
d268c551
C
208 /**
209 * Plugin: ContextReplacementPlugin
210 * Description: Provides context to Angular's use of System.import
211 *
212 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
213 * See: https://github.com/angular/angular/issues/11580
4d19d2f1 214 */
d268c551
C
215 new ContextReplacementPlugin(
216 // The (\\|\/) piece accounts for path separators in *nix and Windows
c16ce1de
C
217 /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
218 helpers.root('src'), // location of your src
219 {
220 // your Angular Async Route paths relative to this root directory
221 }
d268c551
C
222 ),
223
2e92c10b
C
224 /*
225 * Plugin: CopyWebpackPlugin
226 * Description: Copy files and directories in webpack.
227 *
228 * Copies project static assets.
229 *
230 * See: https://www.npmjs.com/package/copy-webpack-plugin
231 */
a8644408 232 // Used by embed.html
2e92c10b
C
233 new CopyWebpackPlugin([
234 {
235 from: 'src/assets',
236 to: 'assets'
237 },
238 {
239 from: 'node_modules/webtorrent/webtorrent.min.js',
240 to: 'assets/webtorrent'
3bb2c7f9 241 },
3bb2c7f9
C
242 {
243 from: 'src/standalone',
244 to: 'standalone'
2e92c10b
C
245 }
246 ]),
247
248 /*
249 * Plugin: HtmlWebpackPlugin
250 * Description: Simplifies creation of HTML files to serve your webpack bundles.
251 * This is especially useful for webpack bundles that include a hash in the filename
252 * which changes every compilation.
253 *
254 * See: https://github.com/ampedandwired/html-webpack-plugin
255 */
256 new HtmlWebpackPlugin({
257 template: 'src/index.html',
4d19d2f1
C
258 title: METADATA.title,
259 chunksSortMode: 'dependency',
260 metadata: METADATA
261 }),
262
263 /*
264 * Plugin: ScriptExtHtmlWebpackPlugin
265 * Description: Enhances html-webpack-plugin functionality
266 * with different deployment options for your scripts including:
267 *
268 * See: https://github.com/numical/script-ext-html-webpack-plugin
269 */
270 new ScriptExtHtmlWebpackPlugin({
3bb2c7f9 271 sync: [ 'webtorrent.min.js' ],
4d19d2f1 272 defaultAttribute: 'defer'
2e92c10b
C
273 }),
274
4d19d2f1
C
275 new WebpackNotifierPlugin({ alwaysNotify: true }),
276
277 /**
278 * Plugin LoaderOptionsPlugin (experimental)
279 *
280 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
281 */
282 new LoaderOptionsPlugin({
283 options: {
284 sassLoader: {
383bfc83
C
285 precision: 10,
286 includePaths: [ helpers.root('src/sass') ]
4d19d2f1
C
287 }
288 }
c16ce1de
C
289 }),
290
c16ce1de
C
291 new ngcWebpack.NgcWebpackPlugin({
292 disabled: !AOT,
293 tsConfig: helpers.root('tsconfig.webpack.json'),
294 resourceOverride: helpers.root('config/resource-override.js')
b99290b1
C
295 }),
296
297 new BundleAnalyzerPlugin({
298 // Can be `server`, `static` or `disabled`.
299 // In `server` mode analyzer will start HTTP server to show bundle report.
300 // In `static` mode single HTML file with bundle report will be generated.
301 // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
302 analyzerMode: 'static',
303 // Path to bundle report file that will be generated in `static` mode.
304 // Relative to bundles output directory.
305 reportFilename: 'report.html',
306 // Automatically open report in default browser
307 openAnalyzer: false,
308 // If `true`, Webpack Stats JSON file will be generated in bundles output directory
309 generateStatsFile: true,
310 // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
311 // Relative to bundles output directory.
312 statsFilename: 'stats.json',
313 // Options for `stats.toJson()` method.
314 // For example you can exclude sources of your modules from stats file with `source: false` option.
315 // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
316 statsOptions: null,
317 // Log level. Can be 'info', 'warn', 'error' or 'silent'.
318 logLevel: 'info'
4d19d2f1 319 })
2e92c10b 320 ],
4a6995be
C
321
322 /*
2e92c10b
C
323 * Include polyfills or mocks for various node stuff
324 * Description: Node configuration
4a6995be 325 *
2e92c10b 326 * See: https://webpack.github.io/docs/configuration.html#node
4a6995be 327 */
2e92c10b 328 node: {
cc3e2d9b 329 global: true,
2e92c10b 330 crypto: 'empty',
4d19d2f1 331 process: true,
2e92c10b
C
332 module: false,
333 clearImmediate: false,
c16ce1de
C
334 setImmediate: false,
335 setInterval: false,
336 setTimeout: false
2e92c10b 337 }
4a6995be 338 }
4a6995be 339}