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.vue
or anindex.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
, ordocs
website 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
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
andApp.vue
, anexample
directory would be generated
withindex.html
,main.{js,ts}
, andApp.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 anexample
vsdocs
, 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
'sbuild
script would be replaced withvue-cli-service build --target lib --name MY_LIBRARY_NAME src/lib.ts
. -
The
package.json
would either not include aserve
script, or theserve
task/script would be updated to serve theexample
application for the library. -
The
yarn.lock
andpackage-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
- Possibly
vue-cli
andvue-cli-service
would be updated to supportrollup
rather than relying on the currentvue-cli-service build --target lib
. - 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?
- Alternatively is there a better way to configure the repository for publishing to a package repository (typically