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