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