]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/config/webpack.dev.js
Better models define typing
[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),
f9b2d2ce
C
124 'process.env': {
125 'ENV': JSON.stringify(METADATA.ENV),
126 'NODE_ENV': JSON.stringify(METADATA.ENV),
127 'HMR': METADATA.HMR
128 }
129 }),
7f82b8ae 130
cc3e2d9b
C
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'
a17bc2c3 142 }
cc3e2d9b
C
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
4d19d2f1
C
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,
383bfc83 202 typeCheck: true,
4d19d2f1
C
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
f9b2d2ce 217 ],
4a6995be
C
218
219 /**
4d19d2f1
C
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 */
f9b2d2ce
C
227 devServer: {
228 port: METADATA.port,
229 host: METADATA.host,
230 historyApiFallback: true,
231 watchOptions: {
8635a2c7 232 ignored: /node_modules/
1840c2f7 233 }
f9b2d2ce
C
234 },
235
236 /*
4d19d2f1
C
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 */
f9b2d2ce 242 node: {
4d19d2f1 243 global: true,
f9b2d2ce 244 crypto: 'empty',
294f80f2 245 fs: 'empty',
f9b2d2ce
C
246 process: true,
247 module: false,
248 clearImmediate: false,
249 setImmediate: false
250 }
251 })
252}