Skip to content

Commit

Permalink
feat: enhanceApp.js (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k authored and yyx990803 committed Apr 16, 2018
1 parent 1884953 commit 37ea038
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dataMixin from './dataMixin'
import NotFound from '@notFound'
import { routes } from '@temp/routes'
import { siteData } from '@temp/siteData'
import enhanceApp from '@temp/enhanceApp'

// suggest dev server restart on base change
if (module.hot) {
Expand Down Expand Up @@ -64,14 +65,20 @@ export function createApp () {
}
})

const app = new Vue({
router,
render (h) {
return h('div', { attrs: { id: 'app' }}, [
h('router-view', { ref: 'layout' })
])
}
})
const options = {}

enhanceApp({ Vue, options, router })

const app = new Vue(
Object.assign(options, {
router,
render (h) {
return h('div', { attrs: { id: 'app' }}, [
h('router-view', { ref: 'layout' })
])
}
})
)

return { app, router }
}
10 changes: 10 additions & 0 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ if (!Object.assign) Object.assign = require('object-assign')`
await writeTemp(`override.styl`, hasUserOverride ? `@import(${JSON.stringify(overridePath)})` : ``)
}

// 6. handle enhanceApp.js
const enhancePath = path.resolve(sourceDir, '.vuepress/enhanceApp.js')
const hasEnhancePath = fs.existsSync(enhancePath)
await writeTemp(
'enhanceApp.js',
hasEnhancePath
? `export { default } from ${JSON.stringify(enhancePath)}`
: `export default function () {}`
)

return options
}

Expand Down

0 comments on commit 37ea038

Please sign in to comment.