This repository has been archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathwebpack.dev.config.js
84 lines (74 loc) · 2.34 KB
/
webpack.dev.config.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
84
const path = require('path');
const webpack = require('webpack');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const HappyPack = require('happypack');
const getHappyPackConfig = require('./happypack');
const devConfig = require('./webpack.base.config');
const config = require('../config');
const url = `http://localhost:${config.dev.port}`;
devConfig.module.rules.unshift({
test: /\.less$/,
use: ['happypack/loader?id=less-dev']
}, {
test: /\.css$/,
use: ['happypack/loader?id=css-dev']
});
devConfig.plugins = (devConfig.plugins || []).concat([
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(config.dev.env)
}
}),
new HappyPack(getHappyPackConfig({
id: 'less-dev',
loaders: ['vue-style-loader', 'css-loader', 'postcss-loader', 'less-loader']
})),
new HappyPack(getHappyPackConfig({
id: 'css-dev',
loaders: ['vue-style-loader', 'css-loader', 'postcss-loader']
})),
new webpack.NoEmitOnErrorsPlugin(),
new OpenBrowserPlugin({ url: url })
]);
// see https://webpack.github.io/docs/webpack-dev-server.html
devConfig.devServer = {
hot: true,
noInfo: false,
quiet: false,
port: config.dev.port,
// #https://github.com/webpack/webpack-dev-server/issues/882
disableHostCheck: true,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
},
inline: true,
// 解决开发模式下 在子路由刷新返回 404 的情景
historyApiFallback: {
index: config.dev.assetsPublicPath
},
stats: {
colors: true,
modules: false
},
contentBase: config.dev.contentBase,
publicPath: config.dev.assetsPublicPath
};
module.exports = Object.assign({}, devConfig, {
entry: {
index: [
'webpack/hot/dev-server',
`webpack-dev-server/client?http://localhost:${config.dev.port}/`,
path.resolve(__dirname, '../gh/page/index.js')
]
},
output: {
filename: '[name].js',
path: config.dev.assetsRoot,
publicPath: config.dev.assetsPublicPath,
sourceMapFilename: '[file].map',
chunkFilename: '[name].js'
},
devtool: 'source-map'
});