0

I created a vuejs2 project (using webpack) with 2 components, I want to publish this project on npm as a package so that I can use all the components inside this project with multiple projects (reusable components).

I published the project on npm npm publish and installed the package using npm install my-components, I found the project inside node_modules but it was with the whole source code, as if I copy/pasted the project there.

Also when I try to run npm build dist I am getting an error:

npm ERR! Darwin 16.6.0

npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dist"

npm ERR! node v6.9.2

npm ERR! npm v3.10.9

npm ERR! missing script: dist

npm ERR! npm ERR! If you need help, you may report this error at: npm ERR!
https://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request: npm ERR!
/Users/myuser/Documents/Projects/my-components/npm-debug.log

Inside my project (https://github.com/Trelllis/my-components), there is a component called vue-version which I can't use and the project my-components isn't resolved.

How can I publish this project properly with all its components?

Thanks

Community
  • 1
  • 1
Alex
  • 5,971
  • 11
  • 42
  • 80
  • 1
    Look at this similar Question https://stackoverflow.com/questions/45298859/how-to-publish-a-library-of-vue-js-components/45299467#45299467 the vue-share template can solve your problem ,its linked there. – Reiner Jul 27 '17 at 09:24

1 Answers1

0

That's normal to have the full code if you included it the npm module. If you want a folder to be removed from npm, you can create a .npmignore at the root of your project, with the same syntax as .gitignore files. Find documentation for npmignore here.

For your second problem, you probably want to run npm run build, which execute this file. At least I see nothing that could lead in your project to a valid use of npm build dist (there is no dist folder). See general documentation for npm scripts, and documentation for npm build.

FitzFish
  • 8,557
  • 2
  • 30
  • 39
  • I ran `npm build` then installed the package, but when importing it (`import Mycomponents from 'my-components'`), I am getting: `Module not found: Error: Can't resolve 'my-components' in '/Users/myuser/Documents/Projects/trellis-admin-ui/src/components'` – Alex Jul 27 '17 at 09:27
  • Why are you trying to run npm build? – FitzFish Jul 27 '17 at 10:29
  • forget about npm build, I am installing my application but the other project couldn't resolve the `vue-version` component – Alex Jul 27 '17 at 10:43
  • How are you trying to import it? – FitzFish Jul 27 '17 at 11:05
  • import vueVersion from 'vue-version' – Alex Jul 27 '17 at 14:53
  • If you want to import it this way, you need to name your package 'vue-version'. Then add the path of your vue version component to your `package.json`, into the field `main`. Can be for example `"main": "dist/vue-version.js"` (assuming you have a dist folder with your compiled component). – FitzFish Jul 27 '17 at 17:17
  • how can I compile each component as a separate file into the dist folder? – Alex Jul 28 '17 at 09:27