-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Description
Updated: Dec 1, 2018 (per conservation)
What problem does this feature solve?
If someone is setting out to build a library with more than one component in it, there isn't a clear correct way to do so. Similarly, there are no best practices provided by the community to stay consistent (or just avoid having to make decisions yourself when rapidly prototyping).
A library option in vue create would create a project intended to be compiled and distributed as a Library/Plugin rather than an Application.
Workflow Differences
-
A library project typically doesn't have an
App.vueor anindex.html, and this changes the way that you might want to develop the application. Notably,vue-cli-service servedoesn't necessarily
have anything "canonical" to serve.A few workflows that might be common:
- Having a
demo,test, ordocswebsite that renders the application (possibly usingvue-cli-service serve). - Having a static page that loads files from
dist, supported by auto re-build (something likevue-cli-service watch?).
- Having a
-
Many library projects typically commit their
distby default (or at least as part of publishing) rather than ignoring it in.gitignore.
What does the proposed API look like?
A vue create --target lib or vue create --target plugin would be added as a command line option
Changes to "Manually select features"
These feature options might be removed:
- Router
- Progressive Web App
Changes to code generation
-
The
publicdirectory would not be generated. -
The
App.vuefile would not be generated. -
Instead of generating,
publicandApp.vue, anexampledirectory would be generated
withindex.html,main.{js,ts}, andApp.vueand a dependency on the library itself.- Possibly this directory would have its own
package.json - Possibly there could be questions during an interactive
vue createto generate anexamplevsdocs, or other testing website stub. - Possibly the generated website could be pre-organized to help document the plugin.
- Possibly this directory would have its own
-
A
lib.{js,ts}file would be generated instead ofmain.{js,ts}, perhaps something like (e.g. for Typescript)const plugin: PluginObject<void> = { install(Vue: VueConstructor) { // Vue.component("MyComponent", MyComponent); // Vue.component("MyOtherComponent", MyOtherComponent); } }; export default plugin;
-
The
package.json'sbuildscript would be replaced withvue-cli-service build --target lib --name MY_LIBRARY_NAME src/lib.ts. -
The
package.jsonwould either not include aservescript, or theservetask/script would be updated to serve theexampleapplication for the library. -
The
yarn.lockandpackage-lock.jsonpatterns would be added to the.gitignorefile.
Additionally, any other code generation changes as appropriate according to community best practices.
Open Questions
- Possibly
vue-cliandvue-cli-servicewould be updated to supportrolluprather than relying on the currentvue-cli-service build --target lib. - Possibly the
distdirectory would be removed from the.gitignoreby default.- Alternatively is there a better way to configure the repository for publishing to a package repository (typically
npm) as a library?
- Alternatively is there a better way to configure the repository for publishing to a package repository (typically