-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.dev.config.js
78 lines (75 loc) · 2.8 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
const path = require('path')
const HtmlWebPackPlugin = require("html-webpack-plugin");
const webpack = require('webpack');
const merge = require('webpack-merge')
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const webpackBase = require('./webpack.base');
const config = require('./config');
const devConfig = merge(webpackBase, {
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader?cacheDirectory', 'eslint-loader']
},
{
test: /\.less|css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', `less-loader?{"sourceMap":true}`]
}),
},
{
test: /\.(png|jpg|gif|svg)$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
}
}]
},
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: 'url-loader',
options: {
limit: 10000,
name: 'static/media/[name].[ext]',
},
},
]
},
devtool: 'eval',
devServer: {
// contentBase: '', //默认webpack-dev-server会为根文件夹提供本地服务器,如果想为另外一个目录下的文件提供本地服务器,应该在这里设置其所在目录(本例设置到"build"目录)
historyApiFallback: true, //在开发单页应用时非常有用,它依赖于HTML5 history API,如果设置为true,所有的跳转将指向index.html
// compress: true, // 开启gzip压缩
hot: true,
host: '0.0.0.0', // 同一局域网段下,可以通过IP (192.168.X.X:8000) 访问
inline: true, //设置为true,当源文件改变时会自动刷新页面
port: config.dev.port, //设置默认监听端口,如果省略,默认为"8083"
proxy: { // 设置代理解决跨域问题
// '/': {
// target: 'http://localhost:8083/', // 目标服务器地址
// secure: false,
// withCredentials: true
// }
}
},
plugins: [
new HtmlWebPackPlugin({
template: "public/index.html",
filename: "index.html",
env: 'development'
}),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"'
}),
new ExtractTextPlugin({
filename: '[name].css'
})
]
})
module.exports = devConfig;