7
votes

I am trying to explore how to expose my Vue component to other projects without publishing to NPM.

I am able to find the below link which shows how to publish a Vue component to NPM : how-to-publish-your-vue-js-component-on-npm-62b67dfb3e58

But I don't want to publish to NPM. Instead, I want to use the created component in another local project.

1

1 Answers

11
votes

You can have a private repository in you package.json

So the library with .vue components

{
  "name": "my-package-with-components",
  "version": "1.0.0",
  "files": [
    "lib/js/components/**.vue"
  ]
}

In the project where you want to use those components

{
   "devDependencies": {
      "my-package-with-components": "git+ssh://git@my/repo.git#master",
   }
}

In you application script you can import the .vue files

import SpecialComponent1 from 'my-package-with-components/lib/js/components/SpecialComponent1.vue';
import SpecialComponent2 from 'my-package-with-components/lib/js/components/SpecialComponent2.vue';

Vue.component('special-component-1', SpecialComponent1);
Vue.component('special-component-2', SpecialComponent2);

You can load a library in NPM from a directory with npm link

cd mylib/ && npm link
cd ../myapp && npm link mylib