-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Halogen dev workflow, with esbuild #1085
Conversation
package.json
Outdated
@@ -30,7 +30,8 @@ | |||
"format": "purs-tidy format-in-place core src bin docs-search", | |||
"format:check": "purs-tidy check core src bin docs-search", | |||
"bundle": "spago bundle -p spago-bin", | |||
"prepublishOnly": "spago build && ./bin/index.dev.js bundle -p spago-bin && ./bin/index.dev.js bundle -p docs-search-client-halogen" | |||
"prepublishOnly": "spago build && ./bin/index.dev.js bundle -p spago-bin && ./bin/index.dev.js bundle -p docs-search-client-halogen", | |||
"halogen:dev": "echo \"#!/usr/bin/env node\n\nimport { main } from './output/Docs.Search.App/index.js'; main();\" | esbuild --platform=browser --format=iife --sourcemap --bundle --outfile=generated-docs/html/docs-search-app.js --loader:.node=file --alias:punycode=punycode/ --watch=forever" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few notes:
spago bundle
only allowsextraArgs
in the spago.yaml configs, not from the command line. So I was forced to use esbuild directly.- Esbuild doesn't know its supposed to invoke the
main
function so I copied the same workarounds thatSpago.Command.Bundle.purs
uses. i.e. it needs the --iife flag, and the main function to be invoked via extra stdin input. --watch=forever
is so that it keeps watching even after stdin stops receiving input. This does the right thing ™️ , it rebuilds when output/ dependencies change. If you run in regular watch mode, you get this error:
[watch] build finished, watching for changes...
[watch] stopped because stdin was closed (use "--watch=forever" to keep watching even after stdin is closed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only allows
extraArgs
in the spago.yaml configs, not from the command line
Oh, that looks like an oversight 😄 I think we have a good argument to add this now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it needs the --iife flag
Why does it need that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it need that?
To bundle for the browser, see esbuild docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Wasn't there some other reason though about why we couldn't use ESM specifically? I thought there was some library that had an issue, but I can't recall which or why.
Windows CI doesn't look happy, but I like the overall looks of this much better. I think we can fix the bundle extraArgs here, so we can use a |
@f-f On Windows, where does spago bundle output go? I inserted a sanity checking step of https://github.com/purescript/spago/actions/runs/6541347144/job/17762743250?pr=1085#step:13:2 |
Yeah, that's very confusing - I'll have a look |
I can't push to your branch (for future PRs you could make branches in this repo so we can all push to them) but I would try to |
@f-f Hey, I'm back and trying to debug this. I found something weird. On Windows only, If you look at the last two workflow runs, you can see the bundle step works when using the globally installed Both are bundling in verbose mode, so there should be lots of console output: ✅ Working: ❌ Failing with very little console output: |
Oh! Of course. Calling an executable to be run with |
This looks great now - thanks @CharlesTaylor7! 👏👏 |
@f-f Alternative to #1072, based on your feedback: #1072 (comment)
This version avoid pulling in
vite
, and just bundles with ESbuild in watch mode.Overall, it's probably less maintenance overhead, but you will have to manually refresh the page index.html file after the bundling completes.