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

injection for vue plugins #892

Closed
kazupon opened this issue Feb 27, 2018 · 3 comments
Closed

injection for vue plugins #892

kazupon opened this issue Feb 27, 2018 · 3 comments

Comments

@kazupon
Copy link
Member

kazupon commented Feb 27, 2018

What problem does this feature solve?

For vue plugins, It's useful to have a code injection points (e.g import, instance options) to main.js.

e.g. vue-cli-plugin-apollo replace main.js
https://github.com/Akryum/vue-cli-plugin-apollo/blob/master/generator/index.js#L81-L90

What does the proposed API look like?

I think that Geneartor API might need to injectToEntryPoint the below:

module.exports = (api, options, rootOptions) => {
   api.injectToEntryPoint({
     import: 'i18n',
     from: './i18n',
     option: 'i18n'
   })
}

In main.js template, I think it can render like the below:

https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/generator/template/src/main.js

import Vue from 'vue'
import App from './App.vue'
<%_ if (options.router) { _%>
import router from './router'
<%_ } _%>
<%_ if (options.vuex) { _%>
import store from './store'
<%_ } _%>
<%_ for(const plugin of options.plugins) { _%>
import <%= plugin.import %> from '<%= plugin.from %>'
<%_ } _%>

Vue.config.productionTip = false

new Vue({
  <%_ if (options.router) { _%>
  router,
  <%_ } _%>
  <%_ if (options.vuex) { _%>
  store,
  <%_ } _%>
  <%_ for(const plugin of options.plugins) { _%>
  <%= plugin.option %>,
  <%_ } _%>
  render: h => h(App)
}).$mount('#app')
@yyx990803
Copy link
Member

I like this idea.

@kazupon
Copy link
Member Author

kazupon commented Mar 1, 2018

@yyx990803
if this spec is ok, I'll try to implentation it. 😉

@yyx990803
Copy link
Member

Closing in favor of #845

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

No branches or pull requests

2 participants