Skip to content

Allow injecting Vue #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: allow injecting Vue
  • Loading branch information
fjc0k committed Apr 16, 2018
commit c493bd6840a7a49ba04ff0f5725e6289fcdb9b8c
13 changes: 13 additions & 0 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ module.exports = async function prepare (sourceDir) {
// 2. generate routes & user components registration code
const routesCode = await genRoutesFile(options)
const componentCode = await genComponentRegistrationFile(options)
const injectCode = await genInjectFile(options)

await writeTemp('routes.js', [
componentCode,
injectCode,
routesCode
].join('\n\n'))

Expand Down Expand Up @@ -250,6 +252,17 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) {
)
}

async function genInjectFile ({ sourceDir }) {
const injectFile = path.resolve(sourceDir, '.vuepress/inject.js')
if (!fs.existsSync(injectFile)) {
return
}
return (
`import inject from ${JSON.stringify(injectFile)}\n` +
`inject(Vue)`
)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe adding a webpack alias to this file and import it in lib/app/app.js would be better

Copy link
Member

@ulivz ulivz Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, This solution would be better.

function sort (arr) {
return arr.sort((a, b) => {
if (a < b) return -1
Expand Down