]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/config/webpack.dev.js
Fix error logging
[github/Chocobozzz/PeerTube.git] / client / config / webpack.dev.js
CommitLineData
4a6995be
C
1const helpers = require('./helpers')
2const webpackMerge = require('webpack-merge') // used to merge webpack configs
cc3e2d9b 3const webpackMergeDll = webpackMerge.strategy({plugins: 'replace'})
4a6995be
C
4const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev
5
6/**
7 * Webpack Plugins
8 */
cc3e2d9b 9const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin')
4a6995be 10const DefinePlugin = require('webpack/lib/DefinePlugin')
ab32b0fc 11const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin')
4d19d2f1 12const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
4a6995be
C
13
14/**
15 * Webpack Constants
16 */
17const ENV = process.env.ENV = process.env.NODE_ENV = 'development'
ab32b0fc
C
18const HOST = process.env.HOST || 'localhost'
19const PORT = process.env.PORT || 3000
4a6995be 20const HMR = helpers.hasProcessFlag('hot')
2e92c10b 21const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
ab32b0fc
C
22 host: HOST,
23 port: PORT,
4a6995be 24 ENV: ENV,
1840c2f7
C
25 HMR: HMR,
26 API_URL: 'http://localhost:9000'
4a6995be
C
27})
28
cc3e2d9b
C
29const DllBundlesPlugin = require('webpack-dll-bundles-plugin').DllBundlesPlugin
30
4a6995be
C
31/**
32 * Webpack configuration
33 *
34 * See: http://webpack.github.io/docs/configuration.html#cli
35 */
f9b2d2ce 36module.exports = function (env) {
c16ce1de 37 return webpackMerge(commonConfig({ env: ENV }), {
4a6995be 38 /**
4d19d2f1
C
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 */
f9b2d2ce 44 devtool: 'cheap-module-source-map',
4a6995be 45
f9b2d2ce 46 /**
4d19d2f1
C
47 * Options affecting the output of the compilation.
48 *
49 * See: http://webpack.github.io/docs/configuration.html#output
50 */
f9b2d2ce
C
51 output: {
52 /**
4d19d2f1
C
53 * The output directory as absolute path (required).
54 *
55 * See: http://webpack.github.io/docs/configuration.html#output-path
56 */
f9b2d2ce
C
57 path: helpers.root('dist'),
58
59 /**
4d19d2f1
C
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 */
f9b2d2ce
C
65 filename: '[name].bundle.js',
66
67 /**
4d19d2f1
C
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 */
f9b2d2ce
C
73 sourceMapFilename: '[name].map',
74
75 /** The filename of non-entry chunks as relative path
4d19d2f1
C
76 * inside the output.path directory.
77 *
78 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
79 */
f9b2d2ce
C
80 chunkFilename: '[id].chunk.js',
81
82 library: 'ac_[name]',
1840c2f7 83 libraryTarget: 'var'
f9b2d2ce 84 },
4a6995be 85
a17bc2c3
C
86 module: {
87
383bfc83
C
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 // ]
a17bc2c3
C
106 },
107
f9b2d2ce
C
108 plugins: [
109
110 /**
4d19d2f1
C
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 */
f9b2d2ce
C
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,
1840c2f7 123 'API_URL': JSON.stringify(METADATA.API_URL),
174d4657 124 'process.version': JSON.stringify(process.version),
f9b2d2ce
C
125 'process.env': {
126 'ENV': JSON.stringify(METADATA.ENV),
127 'NODE_ENV': JSON.stringify(METADATA.ENV),
128 'HMR': METADATA.HMR
129 }
130 }),
7f82b8ae 131
cc3e2d9b
C
132 new DllBundlesPlugin({
133 bundles: {
134 polyfills: [
135 'core-js',
136 {
137 name: 'zone.js',
138 path: 'zone.js/dist/zone.js'
139 },
140 {
141 name: 'zone.js',
142 path: 'zone.js/dist/long-stack-trace-zone.js'
a17bc2c3 143 }
cc3e2d9b
C
144 ],
145 vendor: [
146 '@angular/platform-browser',
147 '@angular/platform-browser-dynamic',
148 '@angular/core',
149 '@angular/common',
150 '@angular/forms',
151 '@angular/http',
152 '@angular/router',
153 '@angularclass/hmr',
154 'rxjs'
155 ]
156 },
157 dllDir: helpers.root('dll'),
158 webpackConfig: webpackMergeDll(commonConfig({env: ENV}), {
159 devtool: 'cheap-module-source-map',
160 plugins: []
161 })
162 }),
163
164 /**
165 * Plugin: AddAssetHtmlPlugin
166 * Description: Adds the given JS or CSS file to the files
167 * Webpack knows about, and put it into the list of assets
168 * html-webpack-plugin injects into the generated html.
169 *
170 * See: https://github.com/SimenB/add-asset-html-webpack-plugin
171 */
172 new AddAssetHtmlPlugin([
173 { filepath: helpers.root(`dll/${DllBundlesPlugin.resolveFile('polyfills')}`) },
174 { filepath: helpers.root(`dll/${DllBundlesPlugin.resolveFile('vendor')}`) }
175 ]),
176
4d19d2f1
C
177 /**
178 * Plugin: NamedModulesPlugin (experimental)
179 * Description: Uses file names as module name.
180 *
181 * See: https://github.com/webpack/webpack/commit/a04ffb928365b19feb75087c63f13cadfc08e1eb
182 */
183 new NamedModulesPlugin(),
184
185 /**
186 * Plugin LoaderOptionsPlugin (experimental)
187 *
188 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
189 */
190 new LoaderOptionsPlugin({
191 debug: true,
192 options: {
193
194 /**
195 * Static analysis linter for TypeScript advanced options configuration
196 * Description: An extensible linter for the TypeScript language.
197 *
198 * See: https://github.com/wbuchwalter/tslint-loader
199 */
200 tslint: {
201 emitErrors: false,
202 failOnHint: false,
383bfc83 203 typeCheck: true,
4d19d2f1
C
204 resourcePath: 'src'
205 },
206
207 // FIXME: Remove
208 // https://github.com/bholloway/resolve-url-loader/issues/36
209 // https://github.com/jtangelder/sass-loader/issues/289
210 context: __dirname,
211 output: {
212 path: helpers.root('dist')
213 }
214
215 }
216 })
217
f9b2d2ce 218 ],
4a6995be
C
219
220 /**
4d19d2f1
C
221 * Webpack Development Server configuration
222 * Description: The webpack-dev-server is a little node.js Express server.
223 * The server emits information about the compilation state to the client,
224 * which reacts to those events.
225 *
226 * See: https://webpack.github.io/docs/webpack-dev-server.html
227 */
f9b2d2ce
C
228 devServer: {
229 port: METADATA.port,
230 host: METADATA.host,
231 historyApiFallback: true,
232 watchOptions: {
8635a2c7 233 ignored: /node_modules/
1840c2f7 234 }
f9b2d2ce
C
235 },
236
237 /*
4d19d2f1
C
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 */
f9b2d2ce 243 node: {
4d19d2f1 244 global: true,
f9b2d2ce 245 crypto: 'empty',
294f80f2 246 fs: 'empty',
f9b2d2ce
C
247 process: true,
248 module: false,
249 clearImmediate: false,
250 setImmediate: false
251 }
252 })
253}