-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathvite-plugin-add-part.js
44 lines (36 loc) · 1.12 KB
/
vite-plugin-add-part.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
// @ts-nocheck
import t from '@babel/types'; // 新增导入
import { createFilter } from '@rollup/pluginutils';
import babelAddPartAttributePlugin from '../plugins/babel-plugin-add-part-attribute.cjs'
const { visitor } = babelAddPartAttributePlugin({ types: t, jsxFactoryName: 'OmiComponent' })
export default function addPartAttributePlugin(options = {}) {
const filter = createFilter(options.include || /\.(jsx?|tsx?|mjs)$/, options.exclude || /node_modules/);
return {
name: 'add-part-attribute',
async transform(code, id) {
if (!filter(id)) return;
const { transformAsync } = await import('@babel/core');
try {
const result = await transformAsync(code, {
filename: id,
plugins: [
function originalPlugin() {
return {
visitor
};
},
],
sourceMaps: true,
configFile: false,
});
return {
code: result.code,
map: result.map,
};
} catch (err) {
console.error(`Error processing ${id}`);
throw err;
}
},
};
}