-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
88 lines (87 loc) · 1.98 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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
mode: 'development',
//入口文件的路径
entry: "./src/index.tsx",
output: {
//打包的输出路径
path: path.resolve(__dirname, "./dist"),
filename: "bundle.js"
},
// 添加需要解析的文件格式
resolve: {
extensions: ['.ts', '.tsx', '.jsx', '.js', '.json', '.scss'],
modules: [path.resolve(__dirname, 'node_modules')]
},
plugins: [
new HtmlWebpackPlugin({
title: 'learn-react',
template: './index.html',
}),
],
module: {
rules: [{
test: /\.js$/,
include: [
path.resolve(__dirname, './src')
],
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ["env", "react"],
plugins: [
["import", { libraryName: "antd", style: 'css' }] // antd按需加载
]
},
}, {
test: /\.(png|jpg|gif)$/,
use: [{
loader: 'file-loader',
options: {
limit: 5 * 1024,
//指定拷贝文件的输出目录
outputPath: 'images/'
}
}]
}, {
test: /\.css$/,
loader: "style-loader!css-loader?modules",
exclude: /node_modules/,
}, {//antd样式处理
test: /\.css$/,
exclude: /src/,
use: [
{ loader: "style-loader", },
{
loader: "css-loader",
options: {
importLoaders: 1
}
}
]
}, {
test: /\.scss$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader"
}],
}, {
test: /\.tsx?$/,
use: ['ts-loader']
}
]
},
devServer: {
contentBase: path.resolve(__dirname, "dist"),
// colors: true, //终端中输出结果为彩色
historyApiFallback: true, //不跳转
inline: true, //实时刷新
port: 8080
},
// 启用sourceMap
devtool: "source-map",
}