Skip to content
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

Unified yarn build --watch command js+css #1

Closed
bbonamin opened this issue Sep 7, 2021 · 9 comments
Closed

Unified yarn build --watch command js+css #1

bbonamin opened this issue Sep 7, 2021 · 9 comments

Comments

@bbonamin
Copy link

bbonamin commented Sep 7, 2021

Hello!

This is fantastic. I've been following along the progress in https://github.com/rails/jsbundling-rails and was wondering how to set up Tailwind. I did a small PoC using it as a postcss plugin but the setup in this gem is SO MUCH NICER.

Now, to use the sister gems, my understanding is that now we need to run yarn build --watch and yarn build:css --watch side by side. Is there a way to merge that into a single command? Perhaps at install time if the other gem is detected we could add yet a third task to package.json such as https://github.com/open-cli-tools/concurrently#why that runs both?

Unfortunately from initial testing concurrently doesn't seem to pass flags to child processes so we'd need a different task for "watch"

@dhh
Copy link
Member

dhh commented Sep 7, 2021

I don't think it's trivial, because some of these watchers kinda take over the terminal. They're not just appending to a log. But if someone figures it out ✌️

@t27duck
Copy link
Contributor

t27duck commented Sep 7, 2021

A common pattern I've seen is to use the concurrently npm package to string together the commands side by side. It would require a separate watch and build command in package.json, though.

@tommasongr
Copy link

tommasongr commented Sep 7, 2021

You can use foreman to start all your processes together.

In your project root create a Procfile.dev file with this configuration:

rails: bin/rails s -p 3000
js: yarn build --watch
css: yarn build:css --watch

And a .foreman file with this configuration:

procfile: Procfile.dev

Then install foreman gem install foreman (they recommend to not put it the bundle)

With this configuration you can simply run foreman start to start all your processes at once

CleanShot 2021-09-07 at 18 24 43@2x

@bbonamin
Copy link
Author

bbonamin commented Sep 7, 2021

Foreman is nice but it introduces complexity such as not being able to summon a REPL/breakpoint in the middle of Rails code (unless you use a "remote" REPL).

I guess that coming from ./bin/webpack-dev-server which takes care of JS + CSS. Or just JS while CSS was being taken care of by Sprockets, it'd be nice to have something similar here!

@tommasongr
Copy link

Foreman is nice but it introduces complexity such as not being able to summon a REPL/breakpoint in the middle of Rails code (unless you use a "remote" REPL).

Yeah that is quite annoying but for simple website projects (where you don't have a lot to debug) I find it quite useful 🙃

@tommasongr
Copy link

Anyway I love this new direction for managing assets in Rails! Especially for js and the speed improvements that ESM or esbuild bring to it.

Being new to Rails and coming from VueJS development where Vite (esbuild) is quite popular I was frustrated by the slow Webpack build time.

I'm looking forward to try importmaps in Rails 7.0 🎉

@dhh
Copy link
Member

dhh commented Sep 8, 2021

Implmented the foreman approach with a bin/dev bin stub. Thanks!

@dhh dhh closed this as completed Sep 8, 2021
@ahoward
Copy link

ahoward commented Jan 5, 2023

perhaps i'll put together a PR but, running with tmux (and the tmuxinator gem) solves all these issues, including being able to interact with any/all subprocesses. the dev experience is sooooo much better than foreman and about a million LOC less that it's almost certainly worth requiring that binary. it is for all possible rails envs afaik

@ritchiey
Copy link

ritchiey commented May 4, 2023

I realise this is an old thread but it might benefit someone to know that https://github.com/DarthSim/overmind is a great foreman replacement that solves the problem of not being able to interact with the processes individually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants