export default function myPlugin() { return { name: 'myplugin', enforce: 'pre', transform(code, id) { if (!/\.vue$/.test(id)) return //找到带有标记的代码,以后估计安装路径直接找 if (isInVue(id)){ // //为全部el开头的组件外面再套一层 // code = wrapElementComponents(code) // code = injectStyles(code) } const css = code if (css) { return { code: css, map: null, } } }, handleHotUpdate(ctx) { const read = ctx.read if (/\.vue$/.test(ctx.file)) { ctx.read = async () => { const code = await read() return `${code}` } } }, } } const regex = /([\s\S]*?)/; function isInVue(id) { return id == 'D:/workspace/RuoYi-Vue/ruoyi-ui/src/views/index.vue' } function wrapElementComponents(code) { // 匹配el-col和el-row的开始标签,并包裹div let wrappedCode = code.replace( /<(el-(row|col))([^>]*)>/g, '<$1$3>