I'm hosting a site on Github pages, and using Jekyll to generate it.
I added Angular and Lodash to my project using npm
, but didn't want to upload 200 odd files to GitHub so I added node_modules
to my .gitignore
file and just made sure they were added as dependencies within package.json
. The problem then becomes that GitHub pages/Jekyll doesn't auto-install the packages when it (Jekyll) generates.
So my question is, how can I use NPM on GitHub pages without actually uploading my node_modules folder into my GitHub repository?
On the other hand, folder node_modules should not be committed to Git. Apart from their big size, commits including them can become distracting. The best solutions would be this: npm install should run in a CI environment that is similar to the production environment.
Never push node_modules. So now that you understand that your dependencies are system specific and might include native modules, you should never assume that your node_modules folder will work in production.
I suggest the default is to not commit the node_modules folder, and instead add it to your . gitignore file. You might have special needs that reverse this decision. I discuss the topic so you can make your own opinion.
You have two options:
Just generate your static files locally and then upload the final website to Github pages (Github can host non Jekyll websites)
Implement a script that after uploading your files to the master branch (in Travies for example), it builds your site and push the changes to the gp-pages branch.
According to the GitHub, you can add a _config.yml file to tell Jekyll to "include" the "node_modules" and "vendors" directories.
See: https://help.github.com/en/articles/configuring-jekyll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With