使用TypeScript
howcode 2022-07-18 0 webpack
# 安装
npm i typescript ts-loader -D
1
# 配置
const path = require("path");
const HtmlWebpackPlugin = require(html - webpack - plugin);
model.exports = {
entry: "./src/app.ts",
mode: "development",
devtool: "line-source-map",
modules: {
rules: [
{
test: "/./ts$/",
use: "ts-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".ts", ".js"],
},
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "./dist"),
},
plugins: [new HtmlWebpackPlugin()],
};
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 初始化
npx tsc --init
1
在 tsconfig.js 文件下面找到 rootDir 和 outDir 修改如下
"rootDir":"./src",
"outDir":"./dist"
1
2
2
评论
- 表情
——暂无评论——