Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share node modules between vue-cli 3 app?

Does anyone know how to specify the NODE_PATH for a vue-cli app? I've tried setting a NODE_PATH environment variable from within my app folder but no luck.

My goal is to move the node_modules folder a couple of directories up as I will be using multiple vue-cli apps and would like to reuse the 180M worth of code for each app!

I've also tried setting the NODE_PATH in package.json but still no luck.

My understanding is that node will look for the modules in the parent directory but it is not working. If someone has a working example with vue-cli specifically, that would be appreciated.

like image 960
Stefan Morris Avatar asked Oct 23 '25 10:10

Stefan Morris


1 Answers

I got it working however I'm not sure if is a best practice. Seems like vue-cli needs a local package to initialize.

So I placed a copy of the node_modules folder in the parent directory and deleted all the packages from my app's node_modules folder, except for the @vue folder and the hidden .bin folder.

Vue uses the local vue-cli package to initialize and then traverses up to the parent folder when it can't find the other dependencies.

This now allows me to have multiple vue-cli apps reusing a single set of default packages. If any of my apps need additional dependencies, I will just install them locally, per app.

like image 73
Stefan Morris Avatar answered Oct 27 '25 04:10

Stefan Morris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!