Skip to content

Commit 48d5e9b

Browse files
committed
fix: update entry file to install vue-router-layout if vue 3
1 parent 09bf274 commit 48d5e9b

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

generator/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ module.exports = (api, _options = {}, rootOptions = {}) => {
2121
api.render('./template')
2222

2323
if (isVue3) {
24+
api.injectImports(
25+
api.entryFile,
26+
`import VueRouterLayout from 'vue-router-layout'`
27+
)
28+
api.transformScript(api.entryFile, require('./inject-use-plugin'))
29+
2430
api.render('./template-vue3')
2531
}
2632

generator/inject-use-plugin.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = (file, api) => {
2+
const j = api.jscodeshift
3+
const root = j(file.source)
4+
5+
const appRoots = root.find(j.CallExpression, (node) => {
6+
if (j.Identifier.check(node.callee) && node.callee.name === 'createApp') {
7+
return true
8+
}
9+
10+
if (
11+
j.MemberExpression.check(node.callee) &&
12+
j.Identifier.check(node.callee.object) &&
13+
node.callee.object.name === 'Vue' &&
14+
j.Identifier.check(node.callee.property) &&
15+
node.callee.property.name === 'createApp'
16+
) {
17+
return true
18+
}
19+
})
20+
21+
appRoots.replaceWith(({ node: createAppCall }) => {
22+
return j.callExpression(
23+
j.memberExpression(createAppCall, j.identifier('use')),
24+
[j.identifier('VueRouterLayout')]
25+
)
26+
})
27+
28+
return root.toSource()
29+
}

0 commit comments

Comments
 (0)