]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/config/webpack.dev.js
42d9ca37ea9f2d1253a9e01ca282917a839ce065
[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 module: {
87
88 // Too slow, life is short
89 // rules: [
90 // {
91 // test: /\.ts$/,
92 // use: [
93 // {
94 // loader: 'tslint-loader',
95 // options: {
96 // configFile: 'tslint.json'
97 // }
98 // }
99 // ],
100 // exclude: [
101 // /\.(spec|e2e)\.ts$/,
102 // /node_modules\//
103 // ]
104 // }
105 // ]
106 },
107
108 plugins: [
109
110 /**
111 * Plugin: DefinePlugin
112 * Description: Define free variables.
113 * Useful for having development builds with debug logging or adding global constants.
114 *
115 * Environment helpers
116 *
117 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
118 */
119 // NOTE: when adding more properties, make sure you include them in custom-typings.d.ts
120 new DefinePlugin({
121 'ENV': JSON.stringify(METADATA.ENV),
122 'HMR': METADATA.HMR,
123 'API_URL': JSON.stringify(METADATA.API_URL),
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 typeCheck: true,
203 resourcePath: 'src'
204 },
205
206 // FIXME: Remove
207 // https://github.com/bholloway/resolve-url-loader/issues/36
208 // https://github.com/jtangelder/sass-loader/issues/289
209 context: __dirname,
210 output: {
211 path: helpers.root('dist')
212 }
213
214 }
215 })
216
217 ],
218
219 /**
220 * Webpack Development Server configuration
221 * Description: The webpack-dev-server is a little node.js Express server.
222 * The server emits information about the compilation state to the client,
223 * which reacts to those events.
224 *
225 * See: https://webpack.github.io/docs/webpack-dev-server.html
226 */
227 devServer: {
228 port: METADATA.port,
229 host: METADATA.host,
230 historyApiFallback: true,
231 watchOptions: {
232 ignored: /node_modules/
233 }
234 },
235
236 /*
237 * Include polyfills or mocks for various node stuff
238 * Description: Node configuration
239 *
240 * See: https://webpack.github.io/docs/configuration.html#node
241 */
242 node: {
243 global: true,
244 crypto: 'empty',
245 fs: 'empty',
246 process: true,
247 module: false,
248 clearImmediate: false,
249 setImmediate: false
250 }
251 })
252 }