Skip to content
This repository was archived by the owner on Jan 23, 2022. It is now read-only.

Commit 9f5a3e2

Browse files
committed
fix: hotfix for renderIndex is -1
fixes #21
1 parent c8305b9 commit 9f5a3e2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

generator/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ module.exports = (api, opts, rootOptions) => {
3939
const lines = contentMain.split(/\r?\n/g)
4040

4141
const renderIndex = lines.findIndex(line => line.match(/createApp\(App\)(\.use\(\w*\))*\.mount\(['"]#app['"]\)/))
42-
const renderContent = lines[renderIndex]
43-
lines[renderIndex] = `const app = createApp(App)`
44-
lines[renderIndex + 1] = `installElementPlus(app)`
45-
lines[renderIndex + 2] = renderContent.replace('createApp\(App\)','app')
4642

47-
fs.writeFileSync(api.resolve(api.entryFile), lines.join(EOL), { encoding: 'utf-8' })
43+
if (renderIndex >= 0) {
44+
const renderContent = lines[renderIndex]
45+
lines[renderIndex] = `const app = createApp(App)`
46+
lines[renderIndex + 1] = `installElementPlus(app)`
47+
lines[renderIndex + 2] = renderContent.replace('createApp\(App\)','app')
48+
49+
fs.writeFileSync(api.resolve(api.entryFile), lines.join(EOL), { encoding: 'utf-8' })
50+
}
4851
})
4952

5053
api.onCreateComplete(() => {

0 commit comments

Comments
 (0)