]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/config/webpack.dev.js
1e975b26133a1df72c461911c33d1c8e451f6b64
[github/Chocobozzz/PeerTube.git] / client / config / webpack.dev.js
1 const helpers = require('./helpers')
2 const webpackMerge = require('webpack-merge') // used to merge webpack configs
3 const webpackMergeDll = webpackMerge.strategy({plugins: 'replace'})
4 const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev
5
6 /**
7 * Webpack Plugins
8 */
9 const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin')
10 const DefinePlugin = require('webpack/lib/DefinePlugin')
11 const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin')
12 const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
13
14 /**
15 * Webpack Constants
16 */
17 const ENV = process.env.ENV = process.env.NODE_ENV = 'development'
18 const HOST = process.env.HOST || 'localhost'
19 const PORT = process.env.PORT || 3000
20 const HMR = helpers.hasProcessFlag('hot')
21 const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
22 host: HOST,
23 port: PORT,
24 ENV: ENV,
25 HMR: HMR
26 })
27
28 const DllBundlesPlugin = require('webpack-dll-bundles-plugin').DllBundlesPlugin
29
30 /**
31 * Webpack configuration
32 *
33 * See: http://webpack.github.io/docs/configuration.html#cli
34 */
35 module.exports = function (env) {
36 return webpackMerge(commonConfig({ env: ENV }), {
37 /**
38 * Developer tool to enhance debugging
39 *
40 * See: http://webpack.github.io/docs/configuration.html#devtool
41 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
42 */
43 devtool: 'cheap-module-source-map',
44
45 /**
46 * Options affecting the output of the compilation.
47 *
48 * See: http://webpack.github.io/docs/configuration.html#output
49 */
50 output: {
51 /**
52 * The output directory as absolute path (required).
53 *
54 * See: http://webpack.github.io/docs/configuration.html#output-path
55 */
56 path: helpers.root('dist'),
57
58 /**
59 * Specifies the name of each output file on disk.
60 * IMPORTANT: You must not specify an absolute path here!
61 *
62 * See: http://webpack.github.io/docs/configuration.html#output-filename
63 */
64 filename: '[name].bundle.js',
65
66 /**
67 * The filename of the SourceMaps for the JavaScript files.
68 * They are inside the output.path directory.
69 *
70 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
71 */
72 sourceMapFilename: '[name].map',
73
74 /** The filename of non-entry chunks as relative path
75 * inside the output.path directory.
76 *
77 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
78 */
79 chunkFilename: '[id].chunk.js',
80
81 library: 'ac_[name]',
82 libraryTarget: 'var',
83
84 publicPath: '/client/'
85 },
86
87 externals: {
88 webtorrent: 'WebTorrent'
89 },
90
91 module: {
92
93 rules: [
94 {
95 test: /\.ts$/,
96 use: [
97 {
98 loader: 'tslint-loader',
99 options: {
100 configFile: 'tslint.json'
101 }
102 }
103 ],
104 exclude: [/\.(spec|e2e)\.ts$/]
105 }
106 ]
107 },
108
109 plugins: [
110
111 /**
112 * Plugin: DefinePlugin
113 * Description: Define free variables.
114 * Useful for having development builds with debug logging or adding global constants.
115 *
116 * Environment helpers
117 *
118 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
119 */
120 // NOTE: when adding more properties, make sure you include them in custom-typings.d.ts
121 new DefinePlugin({
122 'ENV': JSON.stringify(METADATA.ENV),
123 'HMR': METADATA.HMR,
124 'process.env': {
125 'ENV': JSON.stringify(METADATA.ENV),
126 'NODE_ENV': JSON.stringify(METADATA.ENV),
127 'HMR': METADATA.HMR
128 }
129 }),
130
131 new DllBundlesPlugin({
132 bundles: {
133 polyfills: [
134 'core-js',
135 {
136 name: 'zone.js',
137 path: 'zone.js/dist/zone.js'
138 },
139 {
140 name: 'zone.js',
141 path: 'zone.js/dist/long-stack-trace-zone.js'
142 }
143 ],
144 vendor: [
145 '@angular/platform-browser',
146 '@angular/platform-browser-dynamic',
147 '@angular/core',
148 '@angular/common',
149 '@angular/forms',
150 '@angular/http',
151 '@angular/router',
152 '@angularclass/hmr',
153 'rxjs'
154 ]
155 },
156 dllDir: helpers.root('dll'),
157 webpackConfig: webpackMergeDll(commonConfig({env: ENV}), {
158 devtool: 'cheap-module-source-map',
159 plugins: []
160 })
161 }),
162
163 /**
164 * Plugin: AddAssetHtmlPlugin
165 * Description: Adds the given JS or CSS file to the files
166 * Webpack knows about, and put it into the list of assets
167 * html-webpack-plugin injects into the generated html.
168 *
169 * See: https://github.com/SimenB/add-asset-html-webpack-plugin
170 */
171 new AddAssetHtmlPlugin([
172 { filepath: helpers.root(`dll/${DllBundlesPlugin.resolveFile('polyfills')}`) },
173 { filepath: helpers.root(`dll/${DllBundlesPlugin.resolveFile('vendor')}`) }
174 ]),
175
176 /**
177 * Plugin: NamedModulesPlugin (experimental)
178 * Description: Uses file names as module name.
179 *
180 * See: https://github.com/webpack/webpack/commit/a04ffb928365b19feb75087c63f13cadfc08e1eb
181 */
182 new NamedModulesPlugin(),
183
184 /**
185 * Plugin LoaderOptionsPlugin (experimental)
186 *
187 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
188 */
189 new LoaderOptionsPlugin({
190 debug: true,
191 options: {
192
193 /**
194 * Static analysis linter for TypeScript advanced options configuration
195 * Description: An extensible linter for the TypeScript language.
196 *
197 * See: https://github.com/wbuchwalter/tslint-loader
198 */
199 tslint: {
200 emitErrors: false,
201 failOnHint: false,
202 resourcePath: 'src'
203 },
204
205 // FIXME: Remove
206 // https://github.com/bholloway/resolve-url-loader/issues/36
207 // https://github.com/jtangelder/sass-loader/issues/289
208 context: __dirname,
209 output: {
210 path: helpers.root('dist')
211 }
212
213 }
214 })
215
216 ],
217
218 /**
219 * Webpack Development Server configuration
220 * Description: The webpack-dev-server is a little node.js Express server.
221 * The server emits information about the compilation state to the client,
222 * which reacts to those events.
223 *
224 * See: https://webpack.github.io/docs/webpack-dev-server.html
225 */
226 devServer: {
227 port: METADATA.port,
228 host: METADATA.host,
229 historyApiFallback: true,
230 watchOptions: {
231 aggregateTimeout: 300,
232 poll: 1000
233 },
234 outputPath: helpers.root('dist')
235 },
236
237 /*
238 * Include polyfills or mocks for various node stuff
239 * Description: Node configuration
240 *
241 * See: https://webpack.github.io/docs/configuration.html#node
242 */
243 node: {
244 global: true,
245 crypto: 'empty',
246 process: true,
247 module: false,
248 clearImmediate: false,
249 setImmediate: false
250 }
251 })
252 }