Skip to content

Commit

Permalink
build: fix bundling using webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
errfrom committed Jul 11, 2023
1 parent e5c6014 commit 218b70c
Show file tree
Hide file tree
Showing 13 changed files with 1,265 additions and 1,425 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ result-*
/dist/esbuild/*
!/dist/esbuild/index.html
!/dist/esbuild/wrapper.js
!/dist/webpack/
/dist/webpack/*
!/dist/webpack/.gitkeep
output.js
.DS_Store
.idea/
Expand Down
27 changes: 15 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
SHELL := bash
.ONESHELL:
.PHONY: run-dev run-build check-format format query-testnet-tip clean check-explicit-exports
.PHONY: esbuild-bundle esbuild-serve webpack-bundle webpack-serve check-format format query-testnet-tip clean check-explicit-exports
.SHELLFLAGS := -eu -o pipefail -c

ps-sources := $(shell fd --no-ignore-parent -epurs)
nix-sources := $(shell fd --no-ignore-parent -enix --exclude='spago*')
js-sources := $(shell fd --no-ignore-parent -ejs)
ps-entrypoint := Ctl.Examples.ByUrl # points to one of the example PureScript modules in examples/
ps-bundle = spago bundle-module -m ${ps-entrypoint} --to output.js
preview-node-ipc = $(shell docker volume inspect store_node-preview-ipc | jq -r '.[0].Mountpoint')
preprod-node-ipc = $(shell docker volume inspect store_node-preprod-ipc | jq -r '.[0].Mountpoint')

run-dev:
@${ps-bundle} --minify && BROWSER_RUNTIME=1 webpack-dev-server --progress

run-build:
@${ps-bundle} && BROWSER_RUNTIME=1 webpack --mode=production

esbuild-bundle:
@spago build && BROWSER_RUNTIME=1 node esbuild/bundle.js ${ps-entrypoint}
@spago build \
&& cp -rf fixtures dist/esbuild \
&& BROWSER_RUNTIME=1 node esbuild/bundle.js ${ps-entrypoint}

esbuild-serve:
@spago build \
&& cd dist/esbuild \
&& ln -sfn ../../fixtures fixtures \
&& cd ../.. \
&& cp -rf fixtures dist/esbuild \
&& BROWSER_RUNTIME=1 node esbuild/serve.js ${ps-entrypoint}

webpack-bundle:
@spago build \
&& rm -rf dist/webpack/* \
&& cp -rf fixtures/* dist/webpack \
&& BROWSER_RUNTIME=1 webpack --mode=production --env entry=./output/${ps-entrypoint}/index.js

webpack-serve:
@spago build \
&& BROWSER_RUNTIME=1 webpack-dev-server --progress --env entry=./output/${ps-entrypoint}/index.js

.ONESHELL:
check-explicit-exports:
@if grep -rn '(\.\.)' ${ps-sources}; then
Expand Down
4 changes: 3 additions & 1 deletion dist/esbuild/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
</head>

<body>
<script type="module" src="wrapper.js"></script>
<script type="module">
import("./index.js").then(m => m.main());
</script>
Examples source code is located in <i>examples/</i> directory.<br>
</body>
</html>
6 changes: 0 additions & 6 deletions dist/esbuild/wrapper.js

This file was deleted.

Empty file added dist/webpack/.gitkeep
Empty file.
Empty file modified esbuild/bundle.js
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion esbuild/config.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export const buildOptions = {
platform: "browser",
format: "esm",
treeShaking: true,
logLevel: "warning",
logLevel: "error",
};
Empty file modified esbuild/serve.js
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
</head>

<body>
<script type="module" src="./bundle.js"></script>
<script type="module">
import("./bundle.js").then(m => m.main());
</script>
Examples source code is located in <i>examples/</i> directory.<br>
</body>
</html>
Loading

0 comments on commit 218b70c

Please sign in to comment.