-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.production.config.mjs
43 lines (42 loc) · 1.14 KB
/
webpack.production.config.mjs
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
// 引入路径模块
import { resolve as _resolve, dirname } from "path";
import HtmlWebpackPlugin from "html-webpack-plugin";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export default {
// 从哪里开始编译
entry: "./src/index.ts",
// 编译到哪里
output: {
path: _resolve(__dirname, "dist"),
filename: "static/[name].[contenthash].js",
},
// 配置模块规则
module: {
rules: [
{
test: /\.tsx?$/, // .ts或者tsx后缀的文件,就是typescript文件
use: "ts-loader", // 就是上面安装的ts-loader
exclude: "/node-modules/", // 排除node-modules目录
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
],
},
// 模式
mode: "production",
resolve: {
extensions: [".ts", ".js"], // 配置ts文件可以作为模块加载
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: "打工人的一天",
template: "./public/index.html",
}),
],
};