|
1
|
|
|
'use strict' |
|
2
|
|
|
const utils = require('./utils') |
|
3
|
|
|
const webpack = require('webpack') |
|
4
|
|
|
const config = require('../config') |
|
5
|
|
|
const merge = require('webpack-merge') |
|
6
|
|
|
const path = require('path') |
|
7
|
|
|
const baseWebpackConfig = require('./webpack.base.conf') |
|
8
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin') |
|
9
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin') |
|
10
|
|
|
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') |
|
11
|
|
|
const portfinder = require('portfinder') |
|
12
|
|
|
|
|
13
|
|
|
const HOST = process.env.HOST |
|
14
|
|
|
const PORT = process.env.PORT && Number(process.env.PORT) |
|
15
|
|
|
|
|
16
|
|
|
const devWebpackConfig = merge(baseWebpackConfig, { |
|
17
|
|
|
module: { |
|
18
|
|
|
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true }) |
|
19
|
|
|
}, |
|
20
|
|
|
// cheap-module-eval-source-map is faster for development |
|
21
|
|
|
devtool: config.dev.devtool, |
|
22
|
|
|
|
|
23
|
|
|
// these devServer options should be customized in /config/index.js |
|
24
|
|
|
devServer: { |
|
25
|
|
|
clientLogLevel: 'warning', |
|
26
|
|
|
historyApiFallback: { |
|
27
|
|
|
rewrites: [ |
|
28
|
|
|
{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') }, |
|
29
|
|
|
], |
|
30
|
|
|
}, |
|
31
|
|
|
hot: true, |
|
32
|
|
|
contentBase: false, // since we use CopyWebpackPlugin. |
|
33
|
|
|
compress: true, |
|
34
|
|
|
disableHostCheck: true, |
|
35
|
|
|
host: HOST || config.dev.host, |
|
36
|
|
|
port: PORT || config.dev.port, |
|
37
|
|
|
open: config.dev.autoOpenBrowser, |
|
38
|
|
|
overlay: config.dev.errorOverlay |
|
39
|
|
|
? { warnings: false, errors: true } |
|
40
|
|
|
: false, |
|
41
|
|
|
publicPath: config.dev.assetsPublicPath, |
|
42
|
|
|
proxy: config.dev.proxyTable, |
|
43
|
|
|
quiet: true, // necessary for FriendlyErrorsPlugin |
|
44
|
|
|
watchOptions: { |
|
45
|
|
|
poll: config.dev.poll, |
|
46
|
|
|
} |
|
47
|
|
|
}, |
|
48
|
|
|
plugins: [ |
|
49
|
|
|
new webpack.DefinePlugin({ |
|
50
|
|
|
'process.env': require('../config/dev.env') |
|
51
|
|
|
}), |
|
52
|
|
|
new webpack.HotModuleReplacementPlugin(), |
|
53
|
|
|
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update. |
|
54
|
|
|
new webpack.NoEmitOnErrorsPlugin(), |
|
55
|
|
|
// https://github.com/ampedandwired/html-webpack-plugin |
|
56
|
|
|
new HtmlWebpackPlugin({ |
|
57
|
|
|
filename: 'index.html', |
|
58
|
|
|
template: 'index.html', |
|
59
|
|
|
inject: true |
|
60
|
|
|
}), |
|
61
|
|
|
// copy custom static assets |
|
62
|
|
|
new CopyWebpackPlugin([ |
|
63
|
|
|
{ |
|
64
|
|
|
from: path.resolve(__dirname, '../static'), |
|
65
|
|
|
to: config.dev.assetsSubDirectory, |
|
66
|
|
|
ignore: ['.*'] |
|
67
|
|
|
} |
|
68
|
|
|
]) |
|
69
|
|
|
] |
|
70
|
|
|
}) |
|
71
|
|
|
|
|
72
|
|
|
module.exports = new Promise((resolve, reject) => { |
|
73
|
|
|
portfinder.basePort = process.env.PORT || config.dev.port |
|
74
|
|
|
portfinder.getPort((err, port) => { |
|
75
|
|
|
if (err) { |
|
76
|
|
|
reject(err) |
|
77
|
|
|
} else { |
|
78
|
|
|
// publish the new Port, necessary for e2e tests |
|
79
|
|
|
process.env.PORT = port |
|
80
|
|
|
// add port to devServer config |
|
81
|
|
|
devWebpackConfig.devServer.port = port |
|
82
|
|
|
|
|
83
|
|
|
// Add FriendlyErrorsPlugin |
|
84
|
|
|
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({ |
|
85
|
|
|
compilationSuccessInfo: { |
|
86
|
|
|
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`], |
|
87
|
|
|
}, |
|
88
|
|
|
onErrors: config.dev.notifyOnErrors |
|
89
|
|
|
? utils.createNotifierCallback() |
|
90
|
|
|
: undefined |
|
91
|
|
|
})) |
|
92
|
|
|
|
|
93
|
|
|
resolve(devWebpackConfig) |
|
94
|
|
|
} |
|
95
|
|
|
}) |
|
96
|
|
|
}) |
|
97
|
|
|
|