Skip to content

Commit

Permalink
feat: 🚀 适配HBuilder创建的项目
Browse files Browse the repository at this point in the history
  • Loading branch information
Skiyee committed Aug 5, 2024
1 parent bf9d1a2 commit 7fb60cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export default function UniKuRoot(): Plugin {
name: 'vite-plugin-uni-root',
enforce: 'pre',
async transform(code, id) {
const filterMain = createFilter(['src/main.(ts|js)', 'main.(ts|js)'])
const filterMain = createFilter(`${rootPath}/main.(ts|js)`)
if (filterMain(id))
return registerKuApp(code)

const filterKuRoot = createFilter(['src/App.ku.vue'])
const filterKuRoot = createFilter(`${rootPath}/App.ku.vue`)
if (filterKuRoot(id))
return await rebuildKuApp(appKuPath)

Expand Down
4 changes: 2 additions & 2 deletions src/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export async function registerKuApp(code: string) {
}

export async function rebuildKuApp(path: string) {
const rootTagNameRE = /\b(?:KuRootView|ku-root-view)\b/
const rootTagNameRE = /<(KuRootView|ku-root-view)\s*\/>/

const code = await fs.readFile(path, 'utf-8')
const ms = new MagicString(code).replace(rootTagNameRE, 'slot')
const ms = new MagicString(code).replace(rootTagNameRE, '<slot />')

return ms.toString()
}

0 comments on commit 7fb60cc

Please sign in to comment.