Skip to content

Commit 9a8d9d9

Browse files
authored
Bundle npm dependencies using esbuild (#1574)
2 parents 23b7efe + 5f724aa commit 9a8d9d9

File tree

11 files changed

+766
-5
lines changed

11 files changed

+766
-5
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ src/haz3lweb/exercises/**/*.ml linguist-generated
1111

1212
hazel.opam linguist-generated
1313
hazel.opam.locked linguist-generated
14+
package-lock.json linguist-generated
1415

1516
*.md linguist-documentation
1617
docs/** linguist-documentation

.github/workflows/deploy_branches.yml

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ jobs:
1616
path: source
1717
- name: Add the name of the current branch to the environment as BRANCH_NAME
1818
uses: nelonoel/[email protected]
19+
- name: Install node/npm
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 'latest'
23+
- name: Install NPM dependencies
24+
run: npm install
25+
working-directory: ./source
1926
- name: Set-up OCaml
2027
uses: ocaml/setup-ocaml@v3
2128
with:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ hazel.opam.locked.old
5959

6060
# Code coverage
6161
_coverage/
62+
node_modules/**

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ all: dev
99
deps:
1010
opam update
1111
opam install ./hazel.opam.locked --deps-only --with-test --with-doc
12+
npm install
1213

1314
change-deps:
1415
opam update

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ can also be accessed at:
1717

1818
### Short version
1919

20-
If you already have `ocaml` version 5.2.0 and at least version 2.0 of `opam`
20+
If you already have `ocaml` version 5.2.0, at least version 2.0 of `opam`, and `npm`
2121
installed, you can build Hazel by running the following commands.
2222

2323
- `git clone [email protected]:hazelgrove/hazel.git`

docs/Change-JS-Dependencies.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Adding JavaScript Dependencies
2+
3+
Follow these steps to add and manage JavaScript dependencies in the project:
4+
5+
## 1. Add Dependencies to `package.json`
6+
- Open the `package.json` file in the project root.
7+
- Add the required dependencies under the `"dependencies"` section.
8+
Example:
9+
```json
10+
"dependencies": {
11+
"example-library": "^1.0.0"
12+
}
13+
```
14+
15+
## 2. Update the Lock File
16+
- Run the following command to install the new dependencies and update the `package-lock.json` file:
17+
```bash
18+
make deps
19+
```
20+
**Note:** This command runs `npm install` under the hood. It installs the dependencies listed in the `package.json` file and updates the `package-lock.json` file to reflect the exact versions of the installed packages. This ensures consistent dependency resolution across environments.
21+
22+
## 3. Reference Dependencies in JavaScript Files
23+
- Make sure the desired dependency is referenced by `src/haz3lweb/www/prebundle.js`
24+
Example:
25+
```javascript
26+
import exampleLibrary from 'example-library';
27+
28+
exampleLibrary.doSomething();
29+
```
30+
- If you add a new toplevel js file (outside of prebundle.js) you need to ensure it is bundled and included
31+
- Ensure the `dune` build step is configured to use `esbuild` for bundling the JavaScript files.
32+
- This is the current step in `src/haz3lweb/dune`
33+
```dune
34+
(rule
35+
(targets bundled.js)
36+
(action
37+
(run
38+
%{project_root}/node_modules/esbuild/bin/esbuild
39+
prebundle.js
40+
--bundle
41+
--outfile=bundled.js)))
42+
```
43+
- We need the bundled js for every loaded js file we depend on
44+
- This means that dependencies should be added to already bundled files or a new bundle needs to be added.
45+
- The dependencies will be bundled automatically during the build process.

0 commit comments

Comments
 (0)