fix vite plugin

This commit is contained in:
2025-01-17 09:13:55 +08:00
parent b20a2d9849
commit fe3f626290
3 changed files with 21 additions and 4 deletions

View File

@@ -10,9 +10,27 @@ function replaceKucTagsPlugin() {
if (id.endsWith('.vue')) {
const content = await fs.promises.readFile(id, 'utf-8');
return content
const usedComponent = {}
let res = content
.replace(/<\/kuc-([a-zA-Z0-9-]+)(?![0-9-])>/g, (match, p1) => `</kuc-${p1}-1-18-0>`)
.replace(/<kuc-([a-zA-Z0-9-]+)(?![0-9-])([^>]*)>/g, (match, p1, p2) => `<kuc-${p1}-1-18-0${p2}>`);
.replace(/<kuc-([a-zA-Z0-9-]+)(?![0-9-])([^>]*)>/g, (match, p1, p2) => {
usedComponent[p1] = true;
return `<kuc-${p1}-1-18-0${p2}>`
});
if (Object.keys(usedComponent).length) {
let importScript = '<script lang="ts">'
Object.keys(usedComponent).forEach((key) => {
const keyPascal = key.split('-')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join('');
importScript += `import * as Kuc${keyPascal} from "kintone-ui-component/lib/${key}";`
});
importScript += '</script>';
res = importScript + res;
}
return res;
}
}
};