1

I am building a dashboard with ChartJS and OpenLayers installed through NodeJS, so I install packages locally with npm. OpenLayers also must be installed locally through npm, as there is no CDN link for the latest version.

Answers to similar questions usually jump on the "NodeJS" part, stating correctly that NodeJS needs to be hosted somewhere that can run server code. But this is irrelevant to me. The packages I am using don't need to be run "live" on a server, as my application makes no use of server operations. No HTTP requests, no databases etc.

I host my projects on github and use the github pages feature to make them viewable from my portfolio. I just want my static website to be able to use locally installed packages without having to provide a CDN URL. Can I just upload the html, css and js files with all the package folders to a github repository and create a github page out of it? The packages will still work?

Jinglelocks
  • 113
  • 4

1 Answers1

2

You are using npm 'in development' to fetch chart.js files. Your resulting web app doesn't use Node.js 'in production'.

In the software development phase, you use npm to install chart.js, and then you can use it in the software you write, and test it locally. Then there's a build and package phase, durign which you copy the code you need out of node_modules/chart.js/dist to your release folder, and optimise it. There there's a deployment phase.

If your GitHub pages site's Build and deployment source is Deploy from a branch then the build and package phase happens locally on your machine. You could build & package your code manually, or you could script it. Then you commit the release files to the repo and push to deploy it.

If your GitHub pages site's Build and deployment source is GitHub Actions, then your repo contains just your code (not chart.js) and a GitHub workflow file to build & package your code e.g. .github/workflows/build.yaml. The workflow would install npm and npm would install chart.js. This phase must be fully automated, because it's all happening on GitHub's servers.

Go to the repo, Settings, under Build and deployment, see the source select.

Deploy from a branch is simpler, because it's just using GitHub as a web server, so try this method first. GitHub Actions is more professional, more reliable, better for teams, because everything is automated. So if you have the time and inclination, automate the build process first, then use it to implement the site using GitHub Actions.

Megawhat
  • 56
  • 3