forked from big-tutu/roadhogWebpack4
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.development.js
191 lines (188 loc) · 4.6 KB
/
webpack.config.development.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
* Created by wjt12933 on 2018/5/7.
*/
const webpack = require("webpack");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");
var ManifestPlugin = require("webpack-manifest-plugin");
const AddAssetHtmlPlugin = require("add-asset-html-webpack-plugin");
const theme = require("./src/theme");
const bodyParser = require("body-parser");
// console.log('主题变量\r\n', theme);
module.exports = {
entry: path.resolve(__dirname, "src", "index.js"),
devServer: {
// contentBase: path.resolve(__dirname, 'dist'),
host: "0.0.0.0", // 主机地址
port: 8008, // 端口号
open: false,
hot: true,
historyApiFallback: true,
overlay: {
errors: true
},
stats: {
children: false,
chunks: false,
assets: false,
modules: false
},
proxy: {
"/api": {
target: "http://localhost:7000",
changeOrigin: true,
pathRewrite: { "^/api": "" }
}
}
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist"),
publicPath: "/",
chunkFilename: "[name].async.js",
library: "[name]_dll"
},
resolve: {
alias: {
components: path.resolve(__dirname, "src/components/"),
layouts: path.resolve(__dirname, "src/layouts/"),
utils: path.resolve(__dirname, "src/utils/"),
services: path.resolve(__dirname, "src/services/"),
routes: path.resolve(__dirname, "src/routes/"),
models: path.resolve(__dirname, "src/models/")
}
},
module: {
rules: [
{
test: /\.js$/,
include: [path.resolve(__dirname, "src")],
exclude: [],
loader: "babel-loader?cacheDirectory"
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
importLoaders: 1
}
}
]
},
{
test: /\.less$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
sourceMap: true,
importLoaders: 1,
modules: true,
localIdentName: "[name]_[local]-[hash:base64:5]"
}
},
{
loader: "less-loader",
options: {
sourceMap: true,
javascriptEnabled: true,
modifyVars: theme
}
}
],
exclude: /node_modules/
},
{
test: /\.less$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
sourceMap: true,
importLoaders: 1
}
},
{
loader: "less-loader",
options: {
sourceMap: true,
javascriptEnabled: true,
modifyVars: theme
}
}
],
exclude: /src/
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: "url-loader",
options: {
limit: 8192
}
}
]
}
]
},
externals: {
jquery: "jQuery"
},
node: {
fs: "empty",
module: "empty"
},
devtool: "source-map",
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: "styles",
test: /\.(css|less)/,
chunks: "all",
enforce: true
}
}
}
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css"
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "src", "index.ejs"), // 模板
filename: "index.html",
hash: true // 防止缓存
}),
new CleanWebpackPlugin(["dist"]),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, "public")
}
]),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require("./manifest.json")
}),
new AddAssetHtmlPlugin({
filepath: require.resolve('./public/lib/vendors.dll.js'),
includeSourcemap: false,
hash: true,
}),
new webpack.HotModuleReplacementPlugin(), // 调用webpack的热更新插件
new ManifestPlugin()
// new BundleAnalyzerPlugin(),
// new HardSourceWebpackPlugin(),
]
};