]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/config/webpack.common.js
Client: update tslint -> 3.15.1
[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
66698b83 11const WebpackNotifierPlugin = require('webpack-notifier')
4a6995be
C
12
13/*
14 * Webpack Constants
15 */
16const METADATA = {
17 title: 'PeerTube',
ab32b0fc
C
18 baseUrl: '/',
19 isDevServer: helpers.isWebpackDevServer()
4a6995be
C
20}
21
22/*
23 * Webpack configuration
24 *
25 * See: http://webpack.github.io/docs/configuration.html#cli
26 */
27module.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
ab32b0fc 73 modulesDirectories: [ 'node_modules' ]
4a6995be
C
74 },
75
b20b5fed
C
76 output: {
77 publicPath: '/client/'
78 },
79
4a6995be
C
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
4a6995be 93 {
ab32b0fc
C
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')]
4a6995be
C
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$/,
ab32b0fc
C
123 loaders: [
124 'awesome-typescript-loader',
125 'angular2-template-loader',
126 '@angularclass/hmr-loader'
127 ],
4a6995be
C
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
4a6995be
C
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
f0dc9602
C
167 sassLoader: {
168 precision: 10
169 },
170
4a6995be
C
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
4a6995be
C
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 */
7f82b8ae
C
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 ]),
4a6995be
C
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'
66698b83 228 }),
4a6995be 229
66698b83 230 new WebpackNotifierPlugin({ alwaysNotify: true })
4a6995be
C
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',
c21f59d3
C
242 fs: 'empty',
243 events: true,
4a6995be
C
244 module: false,
245 clearImmediate: false,
246 setImmediate: false
247 }
248
249}