Skip to content

Add a library or plugin option to vue create #3052

Open
@kestred

Description

@kestred

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.vue or an index.html, and this changes the way that you might want to develop the application. Notably, vue-cli-service serve doesn't necessarily
    have anything "canonical" to serve.

    A few workflows that might be common:

    • Having a demo, test, or docs website that renders the application (possibly using vue-cli-service serve).
    • Having a static page that loads files from dist, supported by auto re-build (something like vue-cli-service watch?).
  • Many library projects typically commit their dist by 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 public directory would not be generated.

  • The App.vue file would not be generated.

  • Instead of generating, public and App.vue, an example directory would be generated
    with index.html, main.{js,ts}, and App.vue and a dependency on the library itself.

    • Possibly this directory would have its own package.json
    • Possibly there could be questions during an interactive vue create to generate an example vs docs, or other testing website stub.
    • Possibly the generated website could be pre-organized to help document the plugin.
  • A lib.{js,ts} file would be generated instead of main.{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's build script would be replaced with vue-cli-service build --target lib --name MY_LIBRARY_NAME src/lib.ts.

  • The package.json would either not include a serve script, or the serve task/script would be updated to serve the example application for the library.

  • The yarn.lock and package-lock.json patterns would be added to the .gitignore file.

Additionally, any other code generation changes as appropriate according to community best practices.

Open Questions

  1. Possibly vue-cli and vue-cli-service would be updated to support rollup rather than relying on the current vue-cli-service build --target lib.
  2. Possibly the dist directory would be removed from the .gitignore by default.
    • Alternatively is there a better way to configure the repository for publishing to a package repository (typically npm) as a library?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions