forked from fishedee/ant-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
135 lines (125 loc) · 3 KB
/
webpack.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
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
const path = require("path");
const args = require("minimist")(process.argv.slice(2));
const htmlWebpackPlugin = require("html-webpack-plugin");
const cleanWebpackPlugin = require("clean-webpack-plugin");
const copyWebpackPlugin = require("copy-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const isDevelopment = args.mode == "development";
const theme = {};
let webpackConfig = {
entry: "./src/index.js",
output: {
filename: "[name]-[hash].js",
chunkFilename: "[name]-[contenthash].js",
path: path.resolve(__dirname, "dist")
},
devtool: "",
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
"art-template": path.resolve(
__dirname,
"node_modules/art-template/lib/template-web.js"
)
}
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
presets: ["env", "react", "stage-0"],
plugins: [
"transform-decorators-legacy",
"transform-runtime",
["import", { libraryName: "antd", style: true }]
]
}
},
{
test: /\.less$/,
exclude: /node_modules/,
use: [
{ loader: "style-loader" },
{
loader: "css-loader",
options: { importLoaders: 1, modules: true }
},
{
loader: "less-loader",
options: { modifyVars: theme, javascriptEnabled: true }
}
]
},
{
test: /\.less$/,
include: /node_modules/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader", options: { importLoaders: 1 } },
{
loader: "less-loader",
options: { modifyVars: theme, javascriptEnabled: true }
}
]
},
{
test: /\.css$/,
use: [{ loader: "style-loader" }, { loader: "css-loader" }]
}
]
},
plugins: [
new cleanWebpackPlugin(["dist"]),
new htmlWebpackPlugin({
filename: "index.html",
title: "note admin",
template: "./src/index.html"
}),
new copyWebpackPlugin([
{
from: __dirname + "/public",
to: __dirname + "/dist"
}
])
],
optimization: {
splitChunks: {
chunks: "all",
minSize: 1,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: "-",
name: true,
cacheGroups: {
vendors: {
name: "vendors",
test: /[\\/]node_modules[\\/]/,
priority: -10
}
}
},
runtimeChunk: {
name: "webpack"
}
},
devServer: {
host: "0.0.0.0",
disableHostCheck: true,
compress: true,
proxy: {
"/": {
target: "http://localhost:8890",
changeOrigin: true
}
}
}
};
if (!isDevelopment) {
webpackConfig.plugins.push(new BundleAnalyzerPlugin());
}
module.exports = webpackConfig;