-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.js
141 lines (123 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
/**
*
*/
const publicPath ='';
/**
* 样式输入路径
*/
const outputPath = path.resolve(process.cwd(), 'assets');
// process.cwd();
const config = {
mode:'development',
entry:{
'q1':path.resolve(process.cwd(), '@src/q1.ts'),
},
output: {
path:outputPath,
publicPath,
filename:`js/[name].js`,
},
module:{
rules:[
{
test: /\.js$/,
exclude: [
/inc/,
]
},
//打包ts
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: [
/node_modules/,
/inc/,
]
},
//单独打包出 css
{
test:/\.css$/i,
use: [
MiniCssExtractPlugin.loader,
{
loader:'css-loader',
options:{
esModule: false, //这个小心, es 和 commonjs的引入导出不同, 不能混用
}
},
],
exclude: [
/inc/,
]
},
//url-loader打包图片字体
{
test: /\.(jpg|png|gif|woff|svg|eot|ttf)\??.*$/,
use: [
{
loader:"url-loader",
options:{
name:`resource/[name].[ext]`,
limit: 1024*8,
emitFile:true,
esModule: false,
useRelativePath:true,//设置为相对路径
publicPath:'../',
},
}
],
exclude: [
/inc/,
]
},
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
'jquery': path.join(process.cwd(), '/node_modules/jquery/dist/jquery.min.js')
}
},
//表示jquery不需要打包
// externals: {
// jquery: 'font-awesome',
// },
optimization:{
splitChunks: {
minChunks: 1, //默认模块被引用一次就分离
minSize: 1, //提取出的chunk的最小大小
cacheGroups: {
//公用库
// default: {
// name: 'base',
// chunks: 'initial',
// minChunks: 2, //模块被引用2次以上的才抽离
// priority: -20,
// reuseExistingChunk: true,
// },
//拆分第三方库(通过npm|yarn安装的库)
vendors: {
// test: /[\\/]node_modules[\\/](jquery|qs|axios|lodash|@popperjs\/core)[\\/]/,
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'initial',
priority: -10,
reuseExistingChunk: true,
},
}
} //splitChunks end
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
new MiniCssExtractPlugin({
filename: `css/[name].css`,
}),
],
}
module.exports = config;