Code Monkey home page Code Monkey logo

Comments (13)

justinwoo avatar justinwoo commented on June 2, 2024

Personally I use either the normal psc-ide plugins or https://github.com/watchexec/watchexec

from spago.

f-f avatar f-f commented on June 2, 2024

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 on src folder and run build 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. a data Building = NotBuilding | FinalBuild | ShouldBuildAgain in an MVar) 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.

f-f avatar f-f commented on June 2, 2024

Here's Stack's implementation of this feature. It's 100 lines, so it should be easy to port here

from spago.

f-f avatar f-f commented on June 2, 2024

Fix up in #126

from spago.

dlight avatar dlight commented on June 2, 2024

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.

JordanMartinez avatar JordanMartinez commented on June 2, 2024

@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.

dlight avatar dlight commented on June 2, 2024

@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.

JordanMartinez avatar JordanMartinez commented on June 2, 2024

Ah, with that criteria, then yeah, it requires a workaround.

from spago.

dlight avatar dlight commented on June 2, 2024

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.

f-f avatar f-f commented on June 2, 2024

@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.

dlight avatar dlight commented on June 2, 2024

@f-f I just wanted to avoid opening two terminal tabs, that's all

And, integration with Parcel sounds awesome!

from spago.

milesfrain avatar milesfrain commented on June 2, 2024

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.

windmaomao avatar windmaomao commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.