-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
98 lines (94 loc) · 3 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
89
90
91
92
93
94
95
96
97
98
const path = require('path');
const glob = require('glob');
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
// 自动清除打包目录
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const getManyEntry = () => {
const entry = {};
const entryFiles = glob.sync('./src/components/*/index.tsx');
Object.keys(entryFiles).map(index => {
const entryFile = entryFiles[index]
const match = entryFile.match(/src\/(.*)\/index\.tsx/)
const pageName = match && match[1]
const entryName = pageName.split('/')[1];
entry[entryName] = `./src/${pageName}/index.tsx`
})
entry['index'] = `./src/index.ts`;
return {
entry
}
}
const {entry} = getManyEntry();
module.exports = {
mode: 'production',
// 单入口的打包方式
// entry: {
// app: [path.join(__dirname, "../src/index.ts")]
// },
// output: {
// path: path.join(__dirname, '../build'),
// filename: 'js/[name].[hash].js',
// chunkFilename: 'js/[name].[chunkhash].js',
// libraryTarget: "umd"
// },
// 多入口的打包方式
entry,
output: {
path: path.join(__dirname,"./lib"),
filename: '[name].js',
libraryTarget: 'umd',
library: 'xjj-lazy-ui',
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
use: [
{
loader: 'babel-loader',
options: {
babelrc: true,
}
}
],
// 指定需要处理的js文件,与之对应的是exclude(不打包exclude的文件或者目录),exclude的优先级高于 include、test
include: path.join(__dirname, './src')
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
{
test: /\.(sass|scss)$/i,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"]
},
{
test: /\.(png|jpg|jpeg)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
outputPath: 'images',
publicPath:"../images/"
}
}
]
}
]
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: 'style/[name].css'
})
],
devtool: "inline-source-map",
resolve: {
alias: {
componenta: path.join(__dirname, "./src/components"),
src: path.join(__dirname, "./src")
},
extensions: ['.tsx', '.ts', '.jsx', '.js'],
}
}