-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.js
116 lines (115 loc) · 2.82 KB
/
webpack.dev.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const path = require("path");
const HTMLWebpackPlugin = require("html-webpack-plugin");
// 开发环境,不配置任何压缩,任何hash,不提取任何css文件
module.exports = {
entry: {
entry: "./src/index.js",
},
mode: "development",
devtool: "source-map",
devServer: {
port: 3000,
hot: true,
historyApiFallback: true,
},
optimization: {
splitChunks: {
chunks: "all",
},
},
resolve: {
extensions: [".js", "jsx", ".ts", ".tsx"],
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
module: {
rules: [
{
test: /.css$/,
use: [
"thread-loader",
"style-loader",
{
loader: "css-loader",
options: {
modules: {
// 只对文件名后缀是module的文件,进行模块化处理
auto: /\.module\.\w+$/i,
},
},
},
],
include: [path.resolve(__dirname, "./src")],
},
{
test: /.less$/,
use: [
"thread-loader",
"style-loader",
{
loader: "css-loader",
options: {
// 只对文件名后缀是module的文件,进行模块化处理
modules: {
auto: /\.module\.\w+$/i,
},
},
},
{
loader: "less-loader",
options: {
lessOptions: {
javascriptEnabled: true,
},
},
},
],
include: [
path.resolve(__dirname, "./src"),
path.resolve(__dirname, "./node_modules/antd/dist/antd.less"),
],
},
{
test: /.js$/,
use: [
{
loader: "thread-loader",
},
{
loader: "babel-loader",
},
],
include: [path.resolve(__dirname, "./src")],
},
// 使用wp5自带的asset模块替代url、file、raw等loader
{
test: /\.(png|jpg|gif)$/i,
type: "asset",
generator: {
filename: "images/[name].[contenthash:8][ext]",
},
},
{
test: /\.(eot|ttf|otf|woff2?)$/i,
type: "asset",
generator: {
filename: "fonts/[name].[contenthash:8][ext]",
},
},
],
},
plugins: [
new HTMLWebpackPlugin({
title: "Title",
template: path.resolve(__dirname, "./public/index.html"),
favicon: path.resolve(__dirname, "./public/favicon.ico"),
}),
],
output: {
filename: "js/[name].bundle.js",
chunkFilename: "js/chunk.[name].js",
path: path.resolve(__dirname, "dist"),
publicPath: "/", // 写好此路径,防止(开发or生产)服务器找不到打包出来的文件,“/”代表web服务器的根目录
},
};