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