22 lines
825 B
TypeScript
22 lines
825 B
TypeScript
export default function AutdPlugin() {
|
|
return {
|
|
name: 'autd-plugin',
|
|
transform(code: string, id: string) {
|
|
if (!/node_modules/.test(id)) {
|
|
if (id.endsWith('.vue') || id.endsWith('.nvue')) {
|
|
if (/v-auth:([^/<>\s]*)/g.test(code)) {
|
|
code = code.replace(/v-auth:([^/<>\s]*)/g, 'v-if="_auth(\'$1\')"');
|
|
const importStatement = "import {_auth} from \"@/utils/permission\";";
|
|
code = code.replace(/(<script\b [^<&>]*>)/gi, (match: string) => {
|
|
return match + '\n' + importStatement
|
|
})
|
|
}
|
|
}
|
|
}
|
|
return {
|
|
code,
|
|
map: null
|
|
};
|
|
}
|
|
};
|
|
} |