Skip to content

Commit 37ea038

Browse files
fjc0kyyx990803
authored andcommitted
feat: enhanceApp.js (#80)
1 parent 1884953 commit 37ea038

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

lib/app/app.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import dataMixin from './dataMixin'
66
import NotFound from '@notFound'
77
import { routes } from '@temp/routes'
88
import { siteData } from '@temp/siteData'
9+
import enhanceApp from '@temp/enhanceApp'
910

1011
// suggest dev server restart on base change
1112
if (module.hot) {
@@ -64,14 +65,20 @@ export function createApp () {
6465
}
6566
})
6667

67-
const app = new Vue({
68-
router,
69-
render (h) {
70-
return h('div', { attrs: { id: 'app' }}, [
71-
h('router-view', { ref: 'layout' })
72-
])
73-
}
74-
})
68+
const options = {}
69+
70+
enhanceApp({ Vue, options, router })
71+
72+
const app = new Vue(
73+
Object.assign(options, {
74+
router,
75+
render (h) {
76+
return h('div', { attrs: { id: 'app' }}, [
77+
h('router-view', { ref: 'layout' })
78+
])
79+
}
80+
})
81+
)
7582

7683
return { app, router }
7784
}

lib/prepare.js

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ if (!Object.assign) Object.assign = require('object-assign')`
5050
await writeTemp(`override.styl`, hasUserOverride ? `@import(${JSON.stringify(overridePath)})` : ``)
5151
}
5252

53+
// 6. handle enhanceApp.js
54+
const enhancePath = path.resolve(sourceDir, '.vuepress/enhanceApp.js')
55+
const hasEnhancePath = fs.existsSync(enhancePath)
56+
await writeTemp(
57+
'enhanceApp.js',
58+
hasEnhancePath
59+
? `export { default } from ${JSON.stringify(enhancePath)}`
60+
: `export default function () {}`
61+
)
62+
5363
return options
5464
}
5565

0 commit comments

Comments
 (0)