]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/config/webpack.dev.js
Update webpack config
[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 4const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev
202e7223 5const videoEmbedConfig = require('./webpack.video-embed.js')
4a6995be
C
6
7/**
8 * Webpack Plugins
9 */
cc3e2d9b 10const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin')
4a6995be 11const DefinePlugin = require('webpack/lib/DefinePlugin')
ab32b0fc 12const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin')
4d19d2f1 13const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
04de542a 14const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlugin')
4a6995be
C
15
16/**
17 * Webpack Constants
18 */
19const ENV = process.env.ENV = process.env.NODE_ENV = 'development'
ab32b0fc
C
20const HOST = process.env.HOST || 'localhost'
21const PORT = process.env.PORT || 3000
04de542a
C
22const PUBLIC = process.env.PUBLIC_DEV || HOST + ':' + PORT
23const AOT = process.env.BUILD_AOT || helpers.hasNpmFlag('aot')
4a6995be 24const HMR = helpers.hasProcessFlag('hot')
04de542a 25const METADATA = {
ab32b0fc
C
26 host: HOST,
27 port: PORT,
04de542a 28 public: PUBLIC,
4a6995be 29 ENV: ENV,
1840c2f7 30 HMR: HMR,
04de542a 31 AOT: AOT,
1840c2f7 32 API_URL: 'http://localhost:9000'
04de542a 33}
4a6995be 34
cc3e2d9b
C
35const DllBundlesPlugin = require('webpack-dll-bundles-plugin').DllBundlesPlugin
36
4a6995be
C
37/**
38 * Webpack configuration
39 *
40 * See: http://webpack.github.io/docs/configuration.html#cli
41 */
f9b2d2ce 42module.exports = function (env) {
202e7223 43 return [
f9b2d2ce 44
202e7223 45 webpackMerge(commonConfig({ env: ENV }), {
f9b2d2ce 46 /**
202e7223 47 * Developer tool to enhance debugging
4d19d2f1 48 *
202e7223
C
49 * See: http://webpack.github.io/docs/configuration.html#devtool
50 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
4d19d2f1 51 */
202e7223 52 devtool: 'cheap-module-source-map',
f9b2d2ce
C
53
54 /**
202e7223 55 * Options affecting the output of the compilation.
4d19d2f1 56 *
202e7223 57 * See: http://webpack.github.io/docs/configuration.html#output
4d19d2f1 58 */
202e7223
C
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'),
f9b2d2ce 66
202e7223
C
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',
f9b2d2ce 74
202e7223
C
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({
f9b2d2ce 129 'ENV': JSON.stringify(METADATA.ENV),
202e7223
C
130 'HMR': METADATA.HMR,
131 'API_URL': JSON.stringify(METADATA.API_URL),
132 'process.version': JSON.stringify(process.version),
04de542a
C
133 'process.env.ENV': JSON.stringify(METADATA.ENV),
134 'process.env.NODE_ENV': JSON.stringify(METADATA.ENV),
135 'process.env.HMR': METADATA.HMR
202e7223
C
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'
cc3e2d9b 211 },
202e7223
C
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')
a17bc2c3 219 }
202e7223
C
220
221 }
04de542a 222 }),
cc3e2d9b 223
04de542a 224 new HotModuleReplacementPlugin()
202e7223 225 ],
cc3e2d9b 226
4d19d2f1 227 /**
202e7223
C
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.
4d19d2f1 232 *
202e7223 233 * See: https://webpack.github.io/docs/webpack-dev-server.html
4d19d2f1 234 */
202e7223
C
235 devServer: {
236 port: METADATA.port,
237 host: METADATA.host,
238 historyApiFallback: true,
04de542a 239 hot: METADATA.HMR,
202e7223
C
240 watchOptions: {
241 ignored: /node_modules/
242 }
243 },
4d19d2f1 244
202e7223
C
245 /*
246 * Include polyfills or mocks for various node stuff
247 * Description: Node configuration
4d19d2f1 248 *
202e7223 249 * See: https://webpack.github.io/docs/configuration.html#node
4d19d2f1 250 */
202e7223
C
251 node: {
252 global: true,
253 crypto: 'empty',
254 fs: 'empty',
255 process: true,
256 module: false,
257 clearImmediate: false,
258 setImmediate: false
1840c2f7 259 }
202e7223
C
260 }),
261
262 videoEmbedConfig({env: ENV})
263 ]
f9b2d2ce 264}