]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/config/webpack.common.js
Client: fix https warning in make friends
[github/Chocobozzz/PeerTube.git] / client / config / webpack.common.js
CommitLineData
4a6995be
C
1const webpack = require('webpack')
2const helpers = require('./helpers')
3
4/*
5 * Webpack Plugins
6 */
7
ab32b0fc 8const CopyWebpackPlugin = require('copy-webpack-plugin')
4a6995be
C
9const HtmlWebpackPlugin = require('html-webpack-plugin')
10const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin
2e92c10b 11const AssetsPlugin = require('assets-webpack-plugin')
d268c551 12const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
4d19d2f1
C
13const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
14const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
66698b83 15const WebpackNotifierPlugin = require('webpack-notifier')
4a6995be
C
16
17/*
18 * Webpack Constants
19 */
20const METADATA = {
21 title: 'PeerTube',
ab32b0fc
C
22 baseUrl: '/',
23 isDevServer: helpers.isWebpackDevServer()
4a6995be
C
24}
25
26/*
27 * Webpack configuration
28 *
29 * See: http://webpack.github.io/docs/configuration.html#cli
30 */
2e92c10b
C
31module.exports = function (options) {
32 var isProd = options.env === 'production'
33
34 return {
4a6995be 35
2e92c10b
C
36 /*
37 * Cache generated modules and chunks to improve performance for multiple incremental builds.
38 * This is enabled by default in watch mode.
39 * You can pass false to disable it.
40 *
41 * See: http://webpack.github.io/docs/configuration.html#cache
42 */
43 // cache: false,
4a6995be 44
2e92c10b
C
45 /*
46 * The entry point for the bundle
47 * Our Angular.js app
48 *
49 * See: http://webpack.github.io/docs/configuration.html#entry
50 */
51 entry: {
52 'polyfills': './src/polyfills.ts',
53 'vendor': './src/vendor.ts',
54 'main': './src/main.ts'
55 },
b20b5fed 56
4a6995be 57 /*
2e92c10b 58 * Options affecting the resolving of modules.
4a6995be 59 *
2e92c10b 60 * See: http://webpack.github.io/docs/configuration.html#resolve
4a6995be 61 */
2e92c10b
C
62 resolve: {
63 /*
64 * An array of extensions that should be used to resolve modules.
65 *
66 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
67 */
4d19d2f1 68 extensions: [ '.ts', '.js', '.json', '.scss' ],
2e92c10b 69
4d19d2f1 70 modules: [helpers.root('src'), 'node_modules']
2e92c10b 71 },
4a6995be
C
72
73 /*
2e92c10b 74 * Options affecting the normal modules.
4a6995be 75 *
2e92c10b 76 * See: http://webpack.github.io/docs/configuration.html#module
4a6995be 77 */
2e92c10b 78 module: {
4a6995be 79
4d19d2f1 80 rules: [
4a6995be 81
2e92c10b
C
82 /*
83 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
84 *
85 * See: https://github.com/s-panferov/awesome-typescript-loader
86 */
87 {
88 test: /\.ts$/,
89 loaders: [
90 '@angularclass/hmr-loader?pretty=' + !isProd + '&prod=' + isProd,
91 'awesome-typescript-loader',
92 'angular2-template-loader'
93 ],
94 exclude: [/\.(spec|e2e)\.ts$/]
95 },
4a6995be 96
2e92c10b
C
97 /*
98 * Json loader support for *.json files.
99 *
100 * See: https://github.com/webpack/json-loader
101 */
102 {
103 test: /\.json$/,
104 loader: 'json-loader'
105 },
4a6995be 106
2e92c10b 107 {
ad22074a
C
108 test: /\.(sass|scss)$/,
109 loaders: ['css-to-string-loader', 'css-loader?sourceMap', 'resolve-url', 'sass-loader?sourceMap']
2e92c10b 110 },
ad22074a
C
111 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url?limit=10000&minetype=application/font-woff' },
112 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file' },
4a6995be 113
2e92c10b
C
114 /* Raw loader support for *.html
115 * Returns file content as string
116 *
117 * See: https://github.com/webpack/raw-loader
118 */
119 {
120 test: /\.html$/,
121 loader: 'raw-loader',
3bb2c7f9 122 exclude: [ helpers.root('src/index.html'), helpers.root('src/standalone/videos/embed.html') ]
2e92c10b 123 }
4a6995be 124
2e92c10b
C
125 ]
126
127 },
128
4a6995be 129 /*
2e92c10b 130 * Add additional plugins to the compiler.
4a6995be 131 *
2e92c10b 132 * See: http://webpack.github.io/docs/configuration.html#plugins
4a6995be 133 */
2e92c10b
C
134 plugins: [
135 new AssetsPlugin({
136 path: helpers.root('dist'),
137 filename: 'webpack-assets.json',
138 prettyPrint: true
139 }),
140
141 /*
142 * Plugin: ForkCheckerPlugin
143 * Description: Do type checking in a separate process, so webpack don't need to wait.
144 *
145 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
146 */
147 new ForkCheckerPlugin(),
148
149 /*
150 * Plugin: CommonsChunkPlugin
151 * Description: Shares common code between the pages.
152 * It identifies common modules and put them into a commons chunk.
153 *
154 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
155 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
156 */
157 new webpack.optimize.CommonsChunkPlugin({
158 name: [ 'polyfills', 'vendor' ].reverse()
159 }),
160
d268c551
C
161 /**
162 * Plugin: ContextReplacementPlugin
163 * Description: Provides context to Angular's use of System.import
164 *
165 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
166 * See: https://github.com/angular/angular/issues/11580
4d19d2f1 167 */
d268c551
C
168 new ContextReplacementPlugin(
169 // The (\\|\/) piece accounts for path separators in *nix and Windows
170 /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
171 helpers.root('src') // location of your src
172 ),
173
2e92c10b
C
174 /*
175 * Plugin: CopyWebpackPlugin
176 * Description: Copy files and directories in webpack.
177 *
178 * Copies project static assets.
179 *
180 * See: https://www.npmjs.com/package/copy-webpack-plugin
181 */
a8644408 182 // Used by embed.html
2e92c10b
C
183 new CopyWebpackPlugin([
184 {
185 from: 'src/assets',
186 to: 'assets'
187 },
188 {
189 from: 'node_modules/webtorrent/webtorrent.min.js',
190 to: 'assets/webtorrent'
3bb2c7f9
C
191 },
192 {
193 from: 'node_modules/video.js/dist/video.min.js',
194 to: 'assets/video-js'
195 },
196 {
197 from: 'node_modules/video.js/dist/video-js.min.css',
198 to: 'assets/video-js'
199 },
200 {
201 from: 'node_modules/videojs-dock/dist/videojs-dock.min.js',
202 to: 'assets/video-js'
203 },
204 {
205 from: 'node_modules/videojs-dock/dist/videojs-dock.css',
206 to: 'assets/video-js'
207 },
208 {
209 from: 'src/standalone',
210 to: 'standalone'
2e92c10b
C
211 }
212 ]),
213
214 /*
215 * Plugin: HtmlWebpackPlugin
216 * Description: Simplifies creation of HTML files to serve your webpack bundles.
217 * This is especially useful for webpack bundles that include a hash in the filename
218 * which changes every compilation.
219 *
220 * See: https://github.com/ampedandwired/html-webpack-plugin
221 */
222 new HtmlWebpackPlugin({
223 template: 'src/index.html',
4d19d2f1
C
224 title: METADATA.title,
225 chunksSortMode: 'dependency',
226 metadata: METADATA
227 }),
228
229 /*
230 * Plugin: ScriptExtHtmlWebpackPlugin
231 * Description: Enhances html-webpack-plugin functionality
232 * with different deployment options for your scripts including:
233 *
234 * See: https://github.com/numical/script-ext-html-webpack-plugin
235 */
236 new ScriptExtHtmlWebpackPlugin({
3bb2c7f9 237 sync: [ 'webtorrent.min.js' ],
4d19d2f1 238 defaultAttribute: 'defer'
2e92c10b
C
239 }),
240
4d19d2f1
C
241 new WebpackNotifierPlugin({ alwaysNotify: true }),
242
243 /**
244 * Plugin LoaderOptionsPlugin (experimental)
245 *
246 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
247 */
248 new LoaderOptionsPlugin({
249 options: {
250 sassLoader: {
251 precision: 10
252 }
253 }
254 })
2e92c10b 255 ],
4a6995be
C
256
257 /*
2e92c10b
C
258 * Include polyfills or mocks for various node stuff
259 * Description: Node configuration
4a6995be 260 *
2e92c10b 261 * See: https://webpack.github.io/docs/configuration.html#node
4a6995be 262 */
2e92c10b 263 node: {
4d19d2f1 264 global: 'true',
2e92c10b 265 crypto: 'empty',
4d19d2f1 266 process: true,
2e92c10b
C
267 module: false,
268 clearImmediate: false,
269 setImmediate: false
270 }
4a6995be 271 }
4a6995be 272}