]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/config/webpack.common.js
Client: update to angular 2.0
[github/Chocobozzz/PeerTube.git] / client / config / webpack.common.js
... / ...
CommitLineData
1const webpack = require('webpack')
2const helpers = require('./helpers')
3
4/*
5 * Webpack Plugins
6 */
7
8const CopyWebpackPlugin = require('copy-webpack-plugin')
9const HtmlWebpackPlugin = require('html-webpack-plugin')
10const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin
11const AssetsPlugin = require('assets-webpack-plugin')
12const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
13const WebpackNotifierPlugin = require('webpack-notifier')
14
15/*
16 * Webpack Constants
17 */
18const METADATA = {
19 title: 'PeerTube',
20 baseUrl: '/',
21 isDevServer: helpers.isWebpackDevServer()
22}
23
24/*
25 * Webpack configuration
26 *
27 * See: http://webpack.github.io/docs/configuration.html#cli
28 */
29module.exports = function (options) {
30 var isProd = options.env === 'production'
31
32 return {
33 /*
34 * Static metadata for index.html
35 *
36 * See: (custom attribute)
37 */
38 metadata: METADATA,
39
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,
48
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 },
60
61 /*
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
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 },
84
85 /*
86 * Options affecting the normal modules.
87 *
88 * See: http://webpack.github.io/docs/configuration.html#module
89 */
90 module: {
91 /*
92 * An array of applied pre and post loaders.
93 *
94 * See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
95 */
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 ],
108
109 /*
110 * An array of automatically applied loaders.
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.
114 *
115 * See: http://webpack.github.io/docs/configuration.html#module-loaders
116 */
117 loaders: [
118
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 },
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: /\.scss$/,
146 exclude: /node_modules/,
147 loaders: [ 'raw-loader', 'sass-loader' ]
148 },
149
150 {
151 test: /\.(woff2?|ttf|eot|svg)$/,
152 loader: 'url?limit=10000&name=assets/fonts/[hash].[ext]'
153 },
154
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 }
165
166 ]
167
168 },
169
170 sassLoader: {
171 precision: 10
172 },
173
174 /*
175 * Add additional plugins to the compiler.
176 *
177 * See: http://webpack.github.io/docs/configuration.html#plugins
178 */
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
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
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 ],
253
254 /*
255 * Include polyfills or mocks for various node stuff
256 * Description: Node configuration
257 *
258 * See: https://webpack.github.io/docs/configuration.html#node
259 */
260 node: {
261 global: 'window',
262 crypto: 'empty',
263 fs: 'empty',
264 events: true,
265 module: false,
266 clearImmediate: false,
267 setImmediate: false
268 }
269 }
270}