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