]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/config/webpack.dev.js
Fix bad to/cc when undo dislike
[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
202e7223
C
94 plugins: [
95
96 /**
97 * Plugin: DefinePlugin
98 * Description: Define free variables.
99 * Useful for having development builds with debug logging or adding global constants.
100 *
101 * Environment helpers
102 *
103 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
104 */
105 // NOTE: when adding more properties, make sure you include them in custom-typings.d.ts
106 new DefinePlugin({
f9b2d2ce 107 'ENV': JSON.stringify(METADATA.ENV),
202e7223
C
108 'HMR': METADATA.HMR,
109 'API_URL': JSON.stringify(METADATA.API_URL),
110 'process.version': JSON.stringify(process.version),
04de542a
C
111 'process.env.ENV': JSON.stringify(METADATA.ENV),
112 'process.env.NODE_ENV': JSON.stringify(METADATA.ENV),
113 'process.env.HMR': METADATA.HMR
202e7223
C
114 }),
115
116 new DllBundlesPlugin({
117 bundles: {
118 polyfills: [
119 'core-js',
120 {
121 name: 'zone.js',
122 path: 'zone.js/dist/zone.js'
123 },
124 {
125 name: 'zone.js',
126 path: 'zone.js/dist/long-stack-trace-zone.js'
127 }
128 ],
129 vendor: [
130 '@angular/platform-browser',
131 '@angular/platform-browser-dynamic',
132 '@angular/core',
133 '@angular/common',
134 '@angular/forms',
135 '@angular/http',
136 '@angular/router',
137 '@angularclass/hmr',
138 'rxjs'
139 ]
140 },
141 dllDir: helpers.root('dll'),
142 webpackConfig: webpackMergeDll(commonConfig({env: ENV}), {
143 devtool: 'cheap-module-source-map',
144 plugins: []
145 })
146 }),
147
148 /**
149 * Plugin: AddAssetHtmlPlugin
150 * Description: Adds the given JS or CSS file to the files
151 * Webpack knows about, and put it into the list of assets
152 * html-webpack-plugin injects into the generated html.
153 *
154 * See: https://github.com/SimenB/add-asset-html-webpack-plugin
155 */
156 new AddAssetHtmlPlugin([
157 { filepath: helpers.root(`dll/${DllBundlesPlugin.resolveFile('polyfills')}`) },
158 { filepath: helpers.root(`dll/${DllBundlesPlugin.resolveFile('vendor')}`) }
159 ]),
160
161 /**
162 * Plugin: NamedModulesPlugin (experimental)
163 * Description: Uses file names as module name.
164 *
165 * See: https://github.com/webpack/webpack/commit/a04ffb928365b19feb75087c63f13cadfc08e1eb
166 */
167 new NamedModulesPlugin(),
168
169 /**
170 * Plugin LoaderOptionsPlugin (experimental)
171 *
172 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
173 */
174 new LoaderOptionsPlugin({
175 debug: true,
176 options: {
177
178 /**
179 * Static analysis linter for TypeScript advanced options configuration
180 * Description: An extensible linter for the TypeScript language.
181 *
182 * See: https://github.com/wbuchwalter/tslint-loader
183 */
184 tslint: {
185 emitErrors: false,
186 failOnHint: false,
187 typeCheck: true,
188 resourcePath: 'src'
cc3e2d9b 189 },
202e7223
C
190
191 // FIXME: Remove
192 // https://github.com/bholloway/resolve-url-loader/issues/36
193 // https://github.com/jtangelder/sass-loader/issues/289
194 context: __dirname,
195 output: {
196 path: helpers.root('dist')
a17bc2c3 197 }
202e7223
C
198
199 }
04de542a 200 }),
cc3e2d9b 201
04de542a 202 new HotModuleReplacementPlugin()
202e7223 203 ],
cc3e2d9b 204
4d19d2f1 205 /**
202e7223
C
206 * Webpack Development Server configuration
207 * Description: The webpack-dev-server is a little node.js Express server.
208 * The server emits information about the compilation state to the client,
209 * which reacts to those events.
4d19d2f1 210 *
202e7223 211 * See: https://webpack.github.io/docs/webpack-dev-server.html
4d19d2f1 212 */
202e7223
C
213 devServer: {
214 port: METADATA.port,
215 host: METADATA.host,
216 historyApiFallback: true,
04de542a 217 hot: METADATA.HMR,
202e7223
C
218 watchOptions: {
219 ignored: /node_modules/
220 }
221 },
4d19d2f1 222
202e7223
C
223 /*
224 * Include polyfills or mocks for various node stuff
225 * Description: Node configuration
4d19d2f1 226 *
202e7223 227 * See: https://webpack.github.io/docs/configuration.html#node
4d19d2f1 228 */
202e7223
C
229 node: {
230 global: true,
231 crypto: 'empty',
232 fs: 'empty',
233 process: true,
234 module: false,
235 clearImmediate: false,
236 setImmediate: false
1840c2f7 237 }
202e7223
C
238 }),
239
240 videoEmbedConfig({env: ENV})
241 ]
f9b2d2ce 242}