-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config copy 2.js
105 lines (102 loc) · 2.7 KB
/
webpack.config copy 2.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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const isDev = process.env.NODE_ENV === "dev";
const resolve = (dir) => path.join(__dirname, dir);
console.log("process.env.NODE_ENV", process.env.NODE_ENV);
const config = {
entry: "./src/index.js",
output: {
filename: "bundle.js",
path: path.join(__dirname, "bundle"),
// clean: true
},
devtool: "source-map",
module: {
rules: [
{
test: /\.js$/i,
include: resolve('src'),
exclude: /node_modules/,
use: [
{
loader: 'thread-loader', // 开启多进程打包
options: {
worker: 3,
}
},
{
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
cacheDirectory: true
},
},
],
},
{
test: /\.css$/,
// use: ["style-loader", "css-loader", "postcss-loader"], // style-loader:将样式通过 style 标签的形式添加到页面上
use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader"],
},
{
test: /\.(jpe?g|png|gif)$/i,
type: "asset",
generator: {
// 输出文件位置以及文件名
// [ext] 自带 "." 这个与 url-loader 配置不同
filename: "images/[name][hash:8][ext]",
},
parser: {
dataUrlCondition: {
maxSize: 50 * 1024, //超过50kb不转 base64
},
},
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
type: "asset",
generator: {
// 输出文件位置以及文件名
filename: "fonts/[name][hash:8][ext]",
},
parser: {
dataUrlCondition: {
maxSize: 10 * 1024, // 超过100kb不转 base64
},
},
},
],
},
devServer: {
compress: true, // 是否开启gzip压缩
port: 4001,
open: true,
},
resolve: {
alias: {
"@": resolve("src"),
Components: resolve("Components"),
},
extensions: [".js", ".json"],
modules: ["node_modules"],
},
resolveLoader:{
modules: ['node_modules']
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].[contenthash:8].css",
}),
new HtmlWebpackPlugin({
template: "./src/index.html",
}),
new CleanWebpackPlugin(),
],
};
module.exports = (env, argv) => {
console.log("argv.mode=", argv.mode); // 打印 mode(模式) 值
// 这里可以通过不同的模式修改 config 配置
return config;
};