-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.dev.js
143 lines (141 loc) · 4.62 KB
/
webpack.dev.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const webpackConstant = require('./webpack.constant');
const WebpackMerge = require('webpack-merge');
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const { CheckerPlugin } = require('awesome-typescript-loader');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const DefinePlugin = webpack.DefinePlugin;
const WebpackCommon = require('./webpack.base');
module.exports = WebpackMerge(WebpackCommon, {
output: {
path: path.join(__dirname, webpackConstant.OutputPath),
},
devServer: {
contentBase: [path.join(__dirname, webpackConstant.OutputPath)],
compress: true,
https: true,
host: 'localhost',
port: 8080,
hot: true, //启用热替换时必须加上new webpack.HotModuleReplacementPlugin()
historyApiFallback: {
rewrites: [
{ from: /./, to: 'dist/404.html' }
]
},
proxy: {
"/api": {
target: "",
secure: false,
pathRewrite: {
"^/api": ""
},
bypass: (req, res, proxyOptions) => {
// 在函数中你可以访问请求体、响应体和代理选项。必须返回 false 或路径,来跳过代理请求。
if (req.headers.accept.indexOf("html") !== -1) {
console.log("Skipping proxy for browser request.");
return "/index.html";
}
}
}
},
stats: {
assets: true,
colors: true,
errors: true,
errorDetails: true,
performance: true,
// reasons: true, //模块被引入的原因
timings: true,
warnings: true,
},
// stats预置指令
// "errors-only" //只在发生错误时输出
// "minimal" // 只在发生错误 或是 新的编译时输出
// "none" // 没有输出
// "normal" // 标准输出
// "detailed" // 详细输出(从 webpack 3.0.0 开始)
// "verbose" // 全部输出
watchContentBase: true,
watchOptions: {
aggregateTimeout: 1000,
poll: 1000,
ignored: /node_modules/
}
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "awesome-typescript-loader",
options: {
useBabel: false,
useCache: false, //使用babel时打开可减少编译时间
babelCore: undefined, //babel-core不在node_modules中时设置
configFileName: path.join(__dirname, 'tsconfig.dev.json')
}
}
]
},
{
test: /\.html?$/,
use: [
{
loader: 'html-loader',
options: {
minimize: false
}
}
]
},
{
test: /\.css$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader"
},
]
},
{
test: /\.scss$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader"
},
{
loader: "postcss-loader",
},
{
loader: "sass-loader"
}
]
}
]
},
plugins: [
new DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('development')
}
}),
new CopyWebpackPlugin([
{
from: path.join(__dirname, webpackConstant.SrcPublicJsPath, 'webpack-dll'),
to: path.join(__dirname, webpackConstant.OutputPath, webpackConstant.OutputPublicJsPath, 'webpack-dll')
}
]),
new CheckerPlugin(),
new webpack.HotModuleReplacementPlugin()
],
// devtool: 'source-map'
// cheap-module-eval-source-map能在Chrome/Firefox中显示源代码文件
devtool: 'cheap-module-eval-source-map'
});