Skip to content
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

Allow injecting Vue, app, router #80

Merged
merged 4 commits into from
Apr 16, 2018
Merged

Allow injecting Vue, app, router #80

merged 4 commits into from
Apr 16, 2018

Conversation

fjc0k
Copy link
Contributor

@fjc0k fjc0k commented Apr 16, 2018

.vuepress/inject.js:

import Element from 'element-ui'

export default ({ Vue, app, router }) => {
  Vue.use(Element)
}

readme.md:

<el-button>.....</el-button>

@fjc0k
Copy link
Contributor Author

fjc0k commented Apr 16, 2018

@ulivz @egoist Thanks for your suggestions.

This is a clean PR. 😂

Copy link
Member

@yyx990803 yyx990803 left a comment

Choose a reason for hiding this comment

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

I think this is useful, but one change needed: instead of injecting app, we should call the inject function before app is created and pass it the raw options. This way the user can inject additional options into the root instance, for example a Vuex store:

import Vuex from 'vuex'

const store = new Vuex.Store({ ... })

export default ({ Vue, options  }) => {
  Vue.use(Vuex)
  options.store = store
}

@yyx990803
Copy link
Member

Also, I'd change the name from inject.js to enhanceApp.js so it's more explicit.

@fjc0k
Copy link
Contributor Author

fjc0k commented Apr 16, 2018

@yyx990803 哈哈,老大,我想睡觉了。英语不咋好,就不费劲了。

首先,你的建议很棒,我应该是全盘接受了。

其次,通过 enhanceApp.js 其实就可以搞插件了,在其中注册某些组件,比如 demo-box 之类的,就可以在文档里直接用了。

最后,请收下 PR。🤗

lib/app/app.js Outdated
})
const options = {}

enhanceApp({ Vue, options })
Copy link
Member

Choose a reason for hiding this comment

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

We still need router here so users can register extra router hooks 😂

Copy link
Member

Choose a reason for hiding this comment

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

我自己来好了,你早点睡觉吧哈哈。多谢。

@yyx990803 yyx990803 merged commit 37ea038 into vuejs:master Apr 16, 2018
fritx added a commit to we-social/SorryPress that referenced this pull request Apr 24, 2018
@fritx
Copy link

fritx commented Apr 24, 2018

How to inject (define) process.env.* variables like in webpack?

--- updated

Sovled by using configureWebpack

https://vuepress.vuejs.org/config/#configurewebpack
we-social/SorryPress@5913cd1#diff-4761d17fe4adc3128346e6375db1c57aR45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants