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