From 37ea038c6bd1275b2448697f29f3a140583b816a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E5=89=91=E6=88=90?= Date: Tue, 17 Apr 2018 02:01:15 +0800 Subject: [PATCH] feat: enhanceApp.js (#80) --- lib/app/app.js | 23 +++++++++++++++-------- lib/prepare.js | 10 ++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/app/app.js b/lib/app/app.js index c2fa6728..ad7fb767 100644 --- a/lib/app/app.js +++ b/lib/app/app.js @@ -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) { @@ -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 } } diff --git a/lib/prepare.js b/lib/prepare.js index 00c65973..a62dc073 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -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 } -- GitLab