-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.config.js
106 lines (100 loc) · 3.09 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const merge = require('webpack-merge');
const webpackBaseConfig = require('./webpack.base.config.js');
// const url = require('url');
const { resolve } = require('path');
const fs = require('fs');
const root_path = 'dist';
const public_path = '/dist/';
// 写入环境变量
fs.open('./src/config/env.js', 'w', function (err, fd) {
const buf = 'export default "development";';
fs.write(fd, buf, 0, buf.length, 0, function (err, written, buffer){});
});
module.exports = merge(webpackBaseConfig, {
// devtool: '#source-map',
devtool: '#eval-source-map',
output: {
path: resolve(__dirname, root_path),
publicPath: public_path,
filename: '[name].js',
chunkFilename: '[name].chunk.js'
},
devServer: {
// host: '127.0.0.1',
// host: '10.0.0.22',
// host: '192.168.66.199',
host:'0.0.0.0',
port: 8010,
contentBase: "./",//本地服务器所加载的页面所在的目录
//代理
proxy: {
/*'/api/': {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
secure: false,
pathRewrite: {
'^/api': ''
}
},*/
'/api/file': {
target: 'https://ysbd-dev.xbdedu.cn',
changeOrigin: true,
secure: false,
},
'/wechatserver/api/': {
target: 'https://ysbd-dev.xbdedu.cn',
changeOrigin: true,
secure: false,
},
/*
'/wechatserver/api/*': {
target: 'https://ysbd-dev.xbdedu.cn',
changeOrigin: true,
secure: false,
},
*/
},
historyApiFallback: true,//不跳转
// historyApiFallback: {
// index: url.parse(public_path).pathname
// },
inline: true, //实时刷新
hot: false, //热部署
compress: false, //压缩
open: false //打开浏览器
},
plugins: [
// 提取CSS
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true
}),
// 版权信息
// new webpack.BannerPlugin("Copyrights (C) zuv inc."),
// 热部署
// new webpack.HotModuleReplacementPlugin(),
// 提取第三方库
new webpack.optimize.CommonsChunkPlugin({
name: 'vendors',
filename: 'vendors.js'
}),
// new webpack.DefinePlugin({
// 'process.env': {
// NODE_ENV: '"development"'
// }
// }),
// 构建html文件
new HtmlWebpackPlugin({
filename: '../index.html',
template: './src/templates/index.ejs',
inject: false
}),
new webpack.ProvidePlugin({
jQuery: "jquery",
$: "jquery"
}),
]
});