Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use node_modules on Github Pages, without uploading to repo

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?

like image 929
Jamie Barker Avatar asked Apr 18 '17 10:04

Jamie Barker


People also ask

Do I need to upload node_modules to GitHub?

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.

Do I need to push node_modules?

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.

Should I git ignore node_modules?

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.


2 Answers

You have two options:

build your site locally

Just generate your static files locally and then upload the final website to Github pages (Github can host non Jekyll websites)

use CI

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.

like image 198
marcanuy Avatar answered Sep 18 '22 19:09

marcanuy


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

like image 35
Royal Avatar answered Sep 18 '22 19:09

Royal