fix vite plugin
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user