-
Notifications
You must be signed in to change notification settings - Fork 41
/
webpack.dev.conf.js
84 lines (76 loc) · 2.35 KB
/
webpack.dev.conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// webpack.dev.conf.js
'use strict'
const webpack = require('webpack')
const path = require('path')
const merge = require('webpack-merge')
const baseConfig = require('./webpack.config')
// const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const portfinder = require('portfinder')
const HOST = process.env.HOST
const PORT = process.env.PORT && Number(process.env.PORT)
const devWebpackConfig = merge(baseConfig, {
mode: 'development',
module: {
// rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
},
// cheap-module-eval-source-map is faster for development
devtool: 'cheap-module-eval-source-map',
// these devServer options should be customized in /config/index.js
devServer: {
clientLogLevel: 'warning',
// historyApiFallback: {
// rewrites: [
// { from: /.*/, to: path.posix.join('index.html') },
// ],
// },
hot: true,
// contentBase: true, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || '0.0.0.0',
port: PORT || 8080,
overlay: true
? { warnings: false, errors: true }
: false,
publicPath: '/',
// proxy: config.dev.proxyTable,
quiet: true, // necessary for FriendlyErrorsPlugin
watchOptions: {
poll: false,
ignored: /node_modules/
}
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
// new HtmlWebpackPlugin({
// filename: 'index.html',
// template: 'index.html',
// inject: true
// }),
],
// watchOptions: {
// poll: config.dev.poll,
// ignored: /node_modules/
// }
});
module.exports = new Promise((resolve, reject) => {
portfinder.basePort = process.env.PORT || 8080
portfinder.getPort((err, port) => {
if (err) {
reject(err)
} else {
// publish the new Port, necessary for e2e tests
process.env.PORT = port
// add port to devServer config
devWebpackConfig.devServer.port = port
// Add FriendlyErrorsPlugin
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
},
}))
resolve(devWebpackConfig)
}
})
})