Is node_modules folder still needed after Laravel Mix compiled the assets?

Viewed 3344

node_modules folder is quite large in term of size. I wonder if we can delete it after Laravel Mix compile everything? Sure, I tried it before (install jquery) and then delete node_modules folder after Laravel Mix compiled everything. My jquery code still running and there's no error at all. So is it okay?

2 Answers

yes, you can remove it after run:

npm run production

after run this command all necessary codes will save in app.js

and when need node_modules you can download them again with :

npm install

You should never commit your node_modules folder to git. That would take forever. Just commit package.json and package-lock.json.

However, you wouldn't want to have to re-install them everytime you build your code. I checked a large project and the total size is 310 M. What situation do you have where you can't keep that in place?

To directly answer your question, Laravel will never run code from the node_modules folder, all of the code used from there is compiled into app.js, so it is safe to delete if you had to.

Related