Comments (13)
Personally I use either the normal psc-ide plugins or https://github.com/watchexec/watchexec
from spago.
Hi @alex-ketch, and thank you for making the spago-react-basic-starter
!
As Justin already noted, if you use psc-ide with some editor you get this rebuilding for free, and if you're not you can use watchexec (e.g. like watchexec -i src spago build
).
So in the end it is possible, but not super nice (as you have to install another tool), and I agree that it might be worth to just integrate the file watching into Spago.
I probably won't get around implementing this soon, so I'll leave here a draft for a possible implementation:
- depend on
fsnotify
- when the
--watch
flag is specified, watch onsrc
folder and runbuild
on modifications fsnotify
supports debouncing (e.g. if you save the same file twice in a short amount of time, you should build only on the second time), but particular attention should be put on tweaking the debounce value, and probably it'd be necessary to have a semaphore (e.g. adata Building = NotBuilding | FinalBuild | ShouldBuildAgain
in anMVar
) to signal if we are building, and if we should enqueue another build (as you don't want two builds going on at the same time)
from spago.
Here's Stack's implementation of this feature. It's 100 lines, so it should be easy to port here
from spago.
Fix up in #126
from spago.
So.. how do you run parcel (or some other custom command) after every time a build is triggered?
Something like this would be useful:
spago bundle-app --to dist/index.js --watch --run-after "parcel blabla"
from spago.
@dlight I think you need to invert your thinking.
Make parcel
watch for file changes where one of its files (say an HTML file) references the bundled app or module that spago produces (which will cause parcel to watch that file for changes, too) and then make spago bundle its app/module using its watch command.
When you make changes to your source code, spago sees the change and rebundles the app/module, which is seen by parcel and causes parcel to rebuild the page.
from spago.
@JordanMartinez if I understand correctly, this require running two long living processes in two terminal tabs, which is what I'm trying to avoid.
A workaround is running watchexec
, and make it run spago
then parcel
on each invocation.
from spago.
Ah, with that criteria, then yeah, it requires a workaround.
from spago.
Just in case it's useful for someone, I ended up writing this script
#!/bin/bash
function cleanup {
trap - SIGTERM
kill -- -$$
}
trap cleanup SIGINT SIGTERM EXIT
rm -f dist/*
while [[ ! -f dist/app.js ]]; do sleep 0.01; done && \
parcel serve asset index.html -o dist/index.html > \
>(sed 's/^/(parcel): /') 2>&1 &
spago bundle-app --watch -m App -t dist/app.js #> >(sed 's/^/(spago): /') 2>&1
It runs Spago on the foreground to enable running commands, like build
. Parcel hangs if there's no app.js file (even if one is created later), that's why it needs this sleep. I wanted Spago to drive Parcel in order to avoid those kinds of quirks (however, this wouldn't work with parcel serve
anyway).
The commented out part would prefix Spago's output with (spago):
but it doesn't work because Spago appears to not do line buffering when writing to something that isn't a tty, so nothing shows up until ctrl+d -- then everything appears at once (but Parcel works fine - just without colors - so maybe this counts as a Spago bug?)
I tried working around with stdbuf -oL spago bundle-app --watch -m App -t dist/app.js > >(sed 's/^/(spago): /') 2>&1
but it also doesn't work.
from spago.
@dlight just curious about your use-case: why is it a requirement to avoid running two long-lived processes for the watchers?
Also you might be interested in #134 which discusses a possible integration with Parcel (so if that would exist you'd only need to run Parcel and it would call the relevant Spago stuff or keep a watcher and run things in order, etc)
from spago.
@f-f I just wanted to avoid opening two terminal tabs, that's all
And, integration with Parcel sounds awesome!
from spago.
As Justin already noted, if you use psc-ide with some editor you get this rebuilding for free, and if you're not you can use watchexec (e.g. like
watchexec -i src spago build
).
Note for new readers, the -i
"ignore path" flag should be replaced with the -w
"watch path" flag.
@f-f Feel free to edit to prevent additional confusion.
I'm using a combination of these commands in separate terminals for automatic page reloading upon file changes:
watchexec -w src -e purs -- spago bundle-app .......
parcel serve ........
from spago.
I used to use nodemon
but seems not as general as watchexec
.
This works for me, thank you.
watchexec -w src -e purs -- spago test
from spago.
Related Issues (20)
- Diff names when listing workspace packages due to not finding local package
- spago@next installation fails on windows HOT 5
- Issue parsing execArgs flag HOT 2
- `spago upgrade` should use a compatible compiler version if no sets for the current one are available HOT 4
- Create a `.purs-repl` file when running `spago repl`
- `verbose-stats` showing improper stats
- allow to exclude some .purs files from compiling HOT 2
- Metadata error not clear HOT 10
- How to run benchmarks? HOT 2
- "dest already exists" error HOT 2
- Can not find package one directory up HOT 1
- `spago install` `git clone`s for same monorepo package multiple times HOT 1
- Autoinstall missing packages HOT 5
- `spago upgrade` doesn't update package-set registry version HOT 1
- Publish packages with dependencies HOT 6
- Error when adding custom `location` HOT 1
- Add facilities to query the association between package versions and package sets
- Spago fails to build on Windows and Node v 21.7 HOT 4
- Spago database falling out of sync with registry without explicit `spago fetch` HOT 8
- can't build chapter 3 of purescript book HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spago.