team-innovation / vue-sfc-rollup

Quickly generate redistributable Vue components with Rollup
MIT License
696 stars 91 forks source link

How to import from source control and npm link? #110

Closed Soviut closed 3 years ago

Soviut commented 3 years ago

I'm hoping to write a private shared component library that will get used across several projects in our organization.

First, this means needing to install the package from bitbucket since paid npm accounts for private packages aren't an option for us (yet). When I first installed the package from github/bitbucket, the import in Vue failed saying it couldn't find the dependency. After some investigation I realized it was because main in package.json points to the dist directory which only exists when you build. So I performed a build and removed the gitignore of the dist directory.

This worked, it imported without error, but required a rebuild, push and pull every time code in the library changes. So I decided to try using npm link to eliminate the push and pull routine. This also worked, but Vue threw errors when I did a rebuild on the library because the dist directory gets erased a fully rebuilt. Even once the new files are in place, the errors persist and the Vue dev server needs to be restarted. So that means having to temporarily remove the prebuild (and possibly postbuild) scripts from package.json.

So what I'm wondering is if I'm doing this process correctly? Is there anything I can do to simplify this process? Is there an entrypoint I can use without having to build?

mgdodge commented 3 years ago

The issue you are having are related to workflow, not this package. Using npm link is supposed to be the best way to do things, but there are issues with the way webpack and npm link function together. See this comment and also this one for prior research on using npm link in local dev work, along with one possible solution (with mixed results.) One of them also mentions using npm pack as an alternative.

Of course, your org can use github packages which support private packages tied directly to private repos, or even install a private npm registry as well. I have done both of these in the past with great success. I haven't used bit personally, but it's supposed to address this type of scenario as well.

Unfortunately, I am going to have to close this issue, since it's not specifically related to vue-sfc-rollup, but personal workflow choices. Hopefully some of these suggestions will point you in the right direction for your org.