-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
98 lines (97 loc) · 2.35 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
const path = require("path");
const { VueLoaderPlugin } = require("vue-loader");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const DeletePlugin = require("delete-sourcemap-plugin");
/**
* @type {import('webpack').Configuration}
*/
module.exports = {
mode: "production",
entry: {
main: "./src/main.js",
},
devtool: "source-map",
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name]_[fullhash:8].js",
assetModuleFilename: 'assets/[name]_[hash:8][ext][query]',
clean: true,
},
resolve: {
extensions: [".js", ".vue", ".json"], // import引用文件省略后缀
alias: {
vue$: "vue/dist/vue.esm.js",
},
},
devServer: {
static: {
// 配置静态资源存放位置
directory: path.resolve(__dirname, "public"), // 根目录下文件
},
open: true,
},
cache: {
type: "filesystem",
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
module: {
rules: [
{
test: /\.vue$/,
loader: "vue-loader",
},
{
test: /\.js$/,
use: ["babel-loader"],
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
// 'style-loader', // 注:style-loader、MiniCssExtractPlugin.loader不能同时使用
"css-loader",
// {
// loader: "postcss-loader",
// options: {
// sourceMap: true,
// postcssOptions: {
// path: 'postcss.config.js'
// }
// }
// }
],
},
{
test: /\.(gif|png|svg|jpe?g)(\?.*)?$/,
type: "asset/resource",
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
type: "asset/resource",
},
],
},
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "public", "./index.html"),
inject: "body",
hash: true,
}),
new MiniCssExtractPlugin({
filename: "css/[name].[fullhash:8].css",
chunkFilename: "css/[id].[fullhash:8].css",
}),
new DeletePlugin(),
],
};