index.js
5.53 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
const path = require('path')
const fs = require('fs')
const vantComponentNames = require("../vantComponentConf")
const handleGetPatterns = (keyArr) => {
// 这些为公共组件
const defaultArr = [
{
from: "src/components/vant-weapp/wxs",
to: "dist/components/vant-weapp/wxs",
},
{
from: "src/components/vant-weapp/common",
to: "dist/components/vant-weapp/common",
},
{
from: "src/components/vant-weapp/share-sheet/options.wxs",
to: "dist/components/vant-weapp/share-sheet/options.wxs",
},
];
const componentArr = keyArr
.map((componentName) => {
// 同步检测这个文件是否存在
// 因为vant weapp部分组件文件下的不存在 wxs 文件
const componentPath = path.resolve(
__dirname,
`../src/components/vant-weapp/${componentName}/index.wxs`
);
const isState = fs.statSync(componentPath, { throwIfNoEntry: false });
return [
{
from: `src/components/vant-weapp/${componentName}/index.${isState ? "wxs" : "wxss"
}`,
to: `dist/components/vant-weapp/${componentName}/index.${isState ? "wxs" : "wxss"
}`,
},
{
from:
"src/components/vant-weapp/" + componentName + "/index.wxml",
to:
"dist/components/vant-weapp/" + componentName + "/index.wxml",
},
];
})
.flat(Infinity);
return [...defaultArr, ...componentArr];
};
const config = {
projectName: 'swx-weapp',
date: '2022-10-01',
designWidth: 750,
deviceRatio: {
640: 2.34 / 2,
750: 1,
828: 1.81 / 2
},
alias: {
"@/utils": path.resolve(__dirname, "../src/utils"),
"@/vant": path.resolve(__dirname, "../src/components/vant-weapp"),
"@/components": path.resolve(__dirname, "../src/components"),
"@/images": path.resolve(__dirname, "../src/assets/images"),
"@/assets": path.resolve(__dirname, "../src/assets"),
"@/composables": path.resolve(__dirname, "../src/composables"),
"@/api": path.resolve(__dirname, "../src/api"),
"@/stores": path.resolve(__dirname, "../src/stores"),
},
sourceRoot: 'src',
outputRoot: 'dist',
// outputRoot: `dist/${process.env.TARO_ENV}`,
plugins: [
'taro-plugin-pinia',
"tarojs-plugin-platform-miniprogram", // 自定义 wxml 支持
['@tarojs/plugin-framework-vue3', {
mini: {
compilerOptions: {
isCustomElement: tag => ["van-tab", "van-tabs"].includes(tag),
whitespace: 'preserve'
}
}
}],
'@tarojs/plugin-html'
],
defineConstants: {
},
copy: {
patterns: handleGetPatterns(vantComponentNames),
// patterns: [
// // 前面2个是基础的
// {
// from: "src/components/vant-weapp/wxs",
// to: "dist/components/vant-weapp/wxs",
// },
// {
// from: "src/components/vant-weapp/common",
// to: "dist/components/vant-weapp/common",
// },
// // 需要用到vant哪个组件就引入
// {
// from: "src/components/vant-weapp/button",
// to: "dist/components/vant-weapp/button",
// },
// {
// from: "src/components/vant-weapp/info",
// to: "dist/components/vant-weapp/info",
// },
// {
// from: "src/components/vant-weapp/icon",
// to: "dist/components/vant-weapp/icon",
// },
// {
// from: "src/components/vant-weapp/loading",
// to: "dist/components/vant-weapp/loading",
// },
// {
// from: "src/components/vant-weapp/tab",
// to: "dist/components/vant-weapp/tab",
// },
// {
// from: "src/components/vant-weapp/tabs",
// to: "dist/components/vant-weapp/tabs",
// },
// {
// from: "src/components/vant-weapp/sticky",
// to: "dist/components/vant-weapp/sticky",
// },
// ],
options: {
}
},
framework: 'vue3',
mini: {
optimizeMainPackage: {
enable: true
},
webpackChain(chain) {
chain.merge({
module: {
rule: {
mjsScript: {
test: /\.mjs$/,
include: [/pinia/],
use: {
babelLoader: {
loader: require.resolve('babel-loader')
}
}
}
}
}
})
},
postcss: {
pxtransform: {
enable: true,
config: {
// 过滤 vant 组件库的前缀:van-
selectorBlackList: [/van-/],
}
},
url: {
enable: true,
config: {
limit: 1024 // 设定转换尺寸上限
}
},
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
}
},
h5: {
publicPath: '/',
staticDirectory: 'static',
postcss: {
autoprefixer: {
enable: true,
config: {
}
},
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
}
}
}
module.exports = function (merge) {
if (process.env.NODE_ENV === 'development') {
return merge({}, config, require('./dev'))
}
return merge({}, config, require('./prod'))
}