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

Feature: Local Plugins #1841

Closed
mwaldstein opened this issue Jul 13, 2018 · 11 comments
Closed

Feature: Local Plugins #1841

mwaldstein opened this issue Jul 13, 2018 · 11 comments

Comments

@mwaldstein
Copy link

What problem does this feature solve?

We have a number of complex, tightly coupled build processes which take advantage of direct access to the webpack config and starting development servers. In looking to migrate to vue-cli, we don't have the same access without being a plugin which are only loaded via package dependencies. The proposal is to specify local plugins, specific to the project.

While for our case it would be for adding adding commands, we also see the benefit in being able to provide per-project UI add-ons.

Alternatives:

  • Using a file dependency in package.json - What we'll likely do w/out this feature. e.g. have a dependency of 'vue-cli-plugin-OurPlugin': 'file: local/path'. Downside is the need to ensure that npm -i is called prior to any use to keep the copy in node-modules up to date.
  • Splitting code into a separate module and use a git dependency - Besides being a much heavier lift and re-architecting (not wrong, just not feasible at the moment), this is project specific code that doesn't make sense to be separated.
  • Abuse of vue-cli-service inspect - Saving webpack config to a temp file to run dev server, etc.

What does the proposed API look like?

A vue.config.js field -

local-plugins: {
  my-plugin: 'path/relative/to/package.json',
}

Implementation Notes

I can create a PR with a basic implementation, but would like to make sure it is the right approach first.

Approach: Add a function to init to concat local plugins here: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/Service.js#L72

@Akryum
Copy link
Member

Akryum commented Jul 13, 2018

Note that you can already have per-project UI addons with the vue-cli-ui.js file like stated in the docs.

@Akryum
Copy link
Member

Akryum commented Jul 13, 2018

Maybe we could have a similar approach, if there is a vue-cli.js file in the project we treat it as a plugin index.js and from there you are free to require any node modules and pass along the api.

@LinusBorg
Copy link
Member

LinusBorg commented Jul 13, 2018

Someone could write a plugin that loads and runs "local plugins" and publish it on npm :-P

That way we would not need to "bloat" core with it.

@Akryum
Copy link
Member

Akryum commented Jul 13, 2018

Since we have it for the UI, I think it makes sense to have it for the cli-service as well.

@Akryum
Copy link
Member

Akryum commented Jul 13, 2018

It's already done anyway 😹

@Akryum Akryum closed this as completed in f505a8e Jul 13, 2018
@LinusBorg
Copy link
Member

If we do it, let's not create another config file though. I think providing a path in a config option in vue.config.js should be enough.

@LinusBorg
Copy link
Member

Oh - too late 😂

@mwaldstein
Copy link
Author

Holy cow, you guys are impressive - I was all ready to spend some time doing the work and creating a PR... and it's done before I brew another cup of coffee...

Brainstorming a bit: are there other plugin features worth exposing locally? As @LinusBorg points out, there can be a lot of pieces and don't want to litter root too much. Thinking of potential of using the concept of generators to update filetypes - no immediate need, just thinking through impacts...

@Akryum
Copy link
Member

Akryum commented Jul 13, 2018

If you need generator capabilities, it's better to do a plugin (you can even create private scopes on npm for your company).

Akryum pushed a commit that referenced this issue Jul 13, 2018
@Akryum
Copy link
Member

Akryum commented Jul 13, 2018

I changed the API to a vuePlugins.service option in package.json: 0835281#diff-1a6db9047a9cbf03d3f2efd495a8506fR80

@marcus30
Copy link

marcus30 commented Apr 2, 2019

If you need generator capabilities, it's better to do a plugin (you can even create private scopes on npm for your company).

Is it possible to access the GeneratorAPI through the service or would you need to invoke the plugin each time you needed generator capabilities? Something like vue-cli-service generate --component would be outstanding.

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

4 participants