-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
52 lines (51 loc) · 1.45 KB
/
webpack.config.ts
File metadata and controls
52 lines (51 loc) · 1.45 KB
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
const path = require('path')
const HtmlWebPackPlugin = require('html-webpack-plugin')
import webpack, { Configuration } from 'webpack'
import WebpackDevServer from 'webpack-dev-server'
const config: Configuration = {
mode: "development",
//...
entry: "./src/main.tsx", // 替换成tsx
//...
plugins: [
new HtmlWebPackPlugin({
title: 'react app',
filename: 'index.html',
template: './src/index.html'
}),
],
module: {
rules: [
//...,
{
test: /\.(ts|tsx)$/,// 替换成ts|tsx
exclude: /(node_modules|bower_components)/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true
}
}
]
}
//...
]
},
resolve: {
// 将.js|.jsx 删除 替换成.ts|.tsx新增加 .less
extensions: ['.tsx', '.js', '.ts', '.less', '.css']
}
}
// 之前是直接命令行之行的代码,因为使用ts-node 所以使用ts运行webpack-dev-server
const devserver = new WebpackDevServer({
headers: { 'Access-Control-Allow-Origin': '*' },
hot: true, // 热更新
host: '127.0.0.1', // 地址
port: '8081', // 端口
open: true, // 是否自动打开
setupExitSignals: true,
compress: true
}, webpack(config))
// 启动
devserver.start()