gleam icon indicating copy to clipboard operation
gleam copied to clipboard

Bundle JS and CSS instead of relying on unpkg CDN

Open aflatter opened this issue 2 years ago • 3 comments

This PR introduces a build step for the assets required to serve the documentation in order to make it usuable without an internet connection (see #1730). The resulting files can be committed to the repo so that you usually don't need NPM to work on gleam - unless you work on the documentation pages.

To build:

cd compiler-core/templates
npm install
npm run esbuild
git add dist/index.css dist/index.js

There's further potential for clean-up:

  • We could move all of the docs-related JS into a subdirectory to make clear that it's separate from prelude.js
  • We could run a formatter like standard on the JavaScript
  • I think all of the code in gleam.js could be merged into index.js (or the other way around)

aflatter avatar Sep 16 '22 08:09 aflatter

@lpil Here we go 👍 Let me know what you think.

aflatter avatar Sep 16 '22 08:09 aflatter

Hello! Thanks for this!

Could you convert this to just having the files vendored in the repository, the same as we do for the existing assets? We don't want to depend on npm at all or have another build tool.

Hmm, can you expand on your rationale here?

re npm: If we just put the minified versions of each library into the directory, it's hard to track the versions and update them as required.

re esbuild: Gives us a single js/css file to include and lets us work with import instead of the global scope - making things much easier to understand.

Though I can understand the urge to avoid any frontend-specific tooling, I think committing the resulting bundle to the repo strikes an okay balance: Usually you won't need to install/work with these things, but if you need to, the work itself will be easier to understand and more comfortable. Also ideally, we port the JS code to Gleam in the near future. 😉

aflatter avatar Sep 20 '22 17:09 aflatter

I'm sorry but we are not adding any new build tools to the Gleam compiler.

We are actively working to remove other tools that are used in a fashion similar to how this PR works because the update workflow is confusing due to having a specific process but being infrequently used.

Vendoring the files is the most reliable and easiest to understand solution, and upgrading the libraries is easier than upgrading using a version manager in this case.

lpil avatar Sep 22 '22 16:09 lpil

Closing this due to inactivity, please feel free to reopen!

lpil avatar Oct 25 '22 17:10 lpil