]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/config/webpack.common.js
Client: update to angular 2.0
[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')
66698b83 13const WebpackNotifierPlugin = require('webpack-notifier')
4a6995be
C
14
15/*
16 * Webpack Constants
17 */
18const METADATA = {
19 title: 'PeerTube',
ab32b0fc
C
20 baseUrl: '/',
21 isDevServer: helpers.isWebpackDevServer()
4a6995be
C
22}
23
24/*
25 * Webpack configuration
26 *
27 * See: http://webpack.github.io/docs/configuration.html#cli
28 */
2e92c10b
C
29module.exports = function (options) {
30 var isProd = options.env === 'production'
31
32 return {
4a6995be 33 /*
2e92c10b 34 * Static metadata for index.html
4a6995be 35 *
2e92c10b 36 * See: (custom attribute)
4a6995be 37 */
2e92c10b 38 metadata: METADATA,
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: {
56 'polyfills': './src/polyfills.ts',
57 'vendor': './src/vendor.ts',
58 'main': './src/main.ts'
59 },
b20b5fed 60
4a6995be 61 /*
2e92c10b 62 * Options affecting the resolving of modules.
4a6995be 63 *
2e92c10b 64 * See: http://webpack.github.io/docs/configuration.html#resolve
4a6995be 65 */
2e92c10b
C
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' ],
4a6995be 73
2e92c10b
C
74 // Make sure root is src
75 root: helpers.root('src'),
76
77 // remove other default values
78 modulesDirectories: [ 'node_modules' ]
79 },
80
81 output: {
82 publicPath: '/client/'
83 },
4a6995be
C
84
85 /*
2e92c10b 86 * Options affecting the normal modules.
4a6995be 87 *
2e92c10b 88 * See: http://webpack.github.io/docs/configuration.html#module
4a6995be 89 */
2e92c10b 90 module: {
4a6995be 91 /*
2e92c10b 92 * An array of applied pre and post loaders.
4a6995be 93 *
2e92c10b 94 * See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
4a6995be 95 */
2e92c10b
C
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 ],
4a6995be
C
108
109 /*
2e92c10b 110 * An array of automatically applied loaders.
4a6995be 111 *
2e92c10b
C
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.
4a6995be 114 *
2e92c10b 115 * See: http://webpack.github.io/docs/configuration.html#module-loaders
4a6995be 116 */
2e92c10b 117 loaders: [
4a6995be 118
2e92c10b
C
119 /*
120 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
121 *
122 * See: https://github.com/s-panferov/awesome-typescript-loader
123 */
124 {
125 test: /\.ts$/,
126 loaders: [
127 '@angularclass/hmr-loader?pretty=' + !isProd + '&prod=' + isProd,
128 'awesome-typescript-loader',
129 'angular2-template-loader'
130 ],
131 exclude: [/\.(spec|e2e)\.ts$/]
132 },
4a6995be 133
2e92c10b
C
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 },
4a6995be 143
2e92c10b
C
144 {
145 test: /\.scss$/,
146 exclude: /node_modules/,
147 loaders: [ 'raw-loader', 'sass-loader' ]
148 },
f0dc9602 149
2e92c10b
C
150 {
151 test: /\.(woff2?|ttf|eot|svg)$/,
152 loader: 'url?limit=10000&name=assets/fonts/[hash].[ext]'
153 },
4a6995be 154
2e92c10b
C
155 /* Raw loader support for *.html
156 * Returns file content as string
157 *
158 * See: https://github.com/webpack/raw-loader
159 */
160 {
161 test: /\.html$/,
162 loader: 'raw-loader',
163 exclude: [ helpers.root('src/index.html') ]
164 }
4a6995be 165
2e92c10b
C
166 ]
167
168 },
169
170 sassLoader: {
171 precision: 10
172 },
4a6995be
C
173
174 /*
2e92c10b 175 * Add additional plugins to the compiler.
4a6995be 176 *
2e92c10b 177 * See: http://webpack.github.io/docs/configuration.html#plugins
4a6995be 178 */
2e92c10b
C
179 plugins: [
180 new AssetsPlugin({
181 path: helpers.root('dist'),
182 filename: 'webpack-assets.json',
183 prettyPrint: true
184 }),
185
186 /*
187 * Plugin: ForkCheckerPlugin
188 * Description: Do type checking in a separate process, so webpack don't need to wait.
189 *
190 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
191 */
192 new ForkCheckerPlugin(),
193
194 /*
195 * Plugin: CommonsChunkPlugin
196 * Description: Shares common code between the pages.
197 * It identifies common modules and put them into a commons chunk.
198 *
199 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
200 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
201 */
202 new webpack.optimize.CommonsChunkPlugin({
203 name: [ 'polyfills', 'vendor' ].reverse()
204 }),
205
d268c551
C
206 /**
207 * Plugin: ContextReplacementPlugin
208 * Description: Provides context to Angular's use of System.import
209 *
210 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
211 * See: https://github.com/angular/angular/issues/11580
212 */
213 new ContextReplacementPlugin(
214 // The (\\|\/) piece accounts for path separators in *nix and Windows
215 /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
216 helpers.root('src') // location of your src
217 ),
218
2e92c10b
C
219 /*
220 * Plugin: CopyWebpackPlugin
221 * Description: Copy files and directories in webpack.
222 *
223 * Copies project static assets.
224 *
225 * See: https://www.npmjs.com/package/copy-webpack-plugin
226 */
227 new CopyWebpackPlugin([
228 {
229 from: 'src/assets',
230 to: 'assets'
231 },
232 {
233 from: 'node_modules/webtorrent/webtorrent.min.js',
234 to: 'assets/webtorrent'
235 }
236 ]),
237
238 /*
239 * Plugin: HtmlWebpackPlugin
240 * Description: Simplifies creation of HTML files to serve your webpack bundles.
241 * This is especially useful for webpack bundles that include a hash in the filename
242 * which changes every compilation.
243 *
244 * See: https://github.com/ampedandwired/html-webpack-plugin
245 */
246 new HtmlWebpackPlugin({
247 template: 'src/index.html',
248 chunksSortMode: 'dependency'
249 }),
250
251 new WebpackNotifierPlugin({ alwaysNotify: true })
252 ],
4a6995be
C
253
254 /*
2e92c10b
C
255 * Include polyfills or mocks for various node stuff
256 * Description: Node configuration
4a6995be 257 *
2e92c10b 258 * See: https://webpack.github.io/docs/configuration.html#node
4a6995be 259 */
2e92c10b
C
260 node: {
261 global: 'window',
262 crypto: 'empty',
263 fs: 'empty',
264 events: true,
265 module: false,
266 clearImmediate: false,
267 setImmediate: false
268 }
4a6995be 269 }
4a6995be 270}