169 points · by nauman · 5y ago · 97 comments
I'm looking forward to Phoenix 1.6 which ditches Webpack for esbuild. Every step away from the insane churn of the modern frontend world is welcome.
We have recurring Jira tickets for updating npm dependencies every two weeks. One developer is occupied between half a day and two days because the amount of breakage in the npm ecosystem is enormous. It’s ridiculous and sucks the life out of us.
We just use dependabot to issue PRs for updating dependencies, and we merge automatically when tests pass. It's never caused an issue.
It works great but the underlying problem still remains I guess
I still have a few projects running Webpack 1 without issue.
Keeping your dependencies is boring and takes a lot of time, but the alternatives are far worse.
I was able to work with rails & webpacker precisely because I had experience with webpack separately, but webpacker had some weird limitations.
https://sergiotapia.com/phoenix-160-liveview-esbuild-tailwin...
Also medium sucks, please don't use it to write developer blogs. People can't read your article!
Also one limitation by design of esbuild is lack of customization, you cannot hook into esbuild and do your own things, but I read you could with swc.
But either way, both are way faster than the most popular ones.
I don't like the churn either, but ditching X for Y only contributes to the churn.
So am I!
I read Mitchell Hanberg's blog post on using it with 1.5 a while back: https://www.mitchellhanberg.com/how-i-handle-static-assets-i...
I found it compelling but was concerned it was a bit early and not enough others would be using esbuild that issues I hit would be googleable. Now that it's the Phoenix default, that won't be a problem.
Compare with something like NextJS where the aforementioned setup takes almost no effort.
https://world.hey.com/dhh/modern-web-apps-without-javascript...
Still, there's the need to install NPM packages. You can use Skypack as a patch, but ideally you should be able to host all of your JavaScript. I guess you could use `npm` and manually link to those files in your configuration map, there could even be an automated Rake task to do it, but I don't know if that's the direction DHH has in mind.
I doubt it's my incompetence alone - npm is involved in over 25% of Phoenix's issues!
All that to say, Rails is fine. But Node is also fine, if you treat it more like Go (minimal dependencies, lean on the vanilla underpinnings).
"Unless new evidence comes to bear that refutes the basic tenets of this analysis, Rails 7.0 will aim to give you a default setup based on import maps, and leave the Webpacker approach as an optional alternative."
It seems like Tailwind is popular enough now to support guides for more than just JS frameworks and Laravel :)
As I've seen many tutorials that were too complex to set up JIT with Tailwind, I thought it might be helpful to others as well who were having difficulty.
The next version of Rails will eliminate webpacker anyway, so I'll write for it
Tell me where to output my .js, .css and other assets and let me worry about compiling - or not as is often the case.
I think the ideal would be some kind of middle ground: an optional contrib module, plugin, or even just documented pattern that can serve as an officially supported approach without baking a strong opinion directly into the framework.
https://world.hey.com/dhh/modern-web-apps-without-javascript...
Besides Rails / Webpacker 6 and Tailwind with the JIT compiler it also includes Sidekiq, Action Cable and Turbo along with Postgres and Redis.
I'm not married to the idea of Webpacker, but currently it's the most painless way to create bundles and process your CSS and JS even if you mostly use server side templates with sprinkles of JS. I'll switch the example app to what Rails defaults to in the future but right now we're in a limbo state where combining a bunch of other independent watchers (esbuild + Tailwind's watcher) and ESM isn't a better development experience IMO.
With Webpacker and Tailwind's JIT, CSS + JS changes take 100ms and you can further optimize startup times with using Webpack's disk cache. With the above Docker set up it's configured with multi-stage builds so your final Rails app only has the end result of running an assets precompile which only runs with RAILS_ENV=production. The Webpack watcher only runs in development too.
If anyone works with Phoenix instead, a similar example app is here https://github.com/nickjj/docker-phoenix-example. There's also example apps for Flask, Django, Node and Play too if you replace the name of the repo. All of them go over the motions of setting up a base line app with Tailwind and Webpack plus whatever else is idiomatic in that stack.
Plot twist: For the Flask, Django, Phoenix, Node and Play examples I've used nearly the same Webpack config for 2 years and I continuously keep Webpack and all of the JS dependencies up to date. There hasn't been any issues at all. I wouldn't consider myself an advanced front-end developer either. I glanced their docs, found something that works and stuck with it.
When someone tells me to ‘invoke these 3 magic incantations’, I can sort of keep track of it. But here it seems like the instructions are to invoke these 300 magic incantations.
Having to jump through all these hoops (I'll note that one of the suggested gems is Devise, which provides a framework for user authentication) suggests either this is very much no longer the case or this is tacking on a lot of stuff Rails was never intended to use, which could be fun to maintain down the line.
Devise is common for user authentication (and good choice, in my opinion) but it is extremely opinionated and does not like you departing from the blessed path.
Rails tends to avoid enforcing patterns beyond the base building blocks of MVC. User authentication is out of scope. (Turbo links is strongly opinionated but also very limited and very easy to remove.)
This sounds like the second of my options i.e. gl;hf when the next major Rails release comes around.
Also - I noticed the author says "foreman is the best way to develop locally". I encourage the author to give overmind a try - it is a drop in, more featureful replacement for foreman. I love it.
I'm glad to see that both rails and phoenix guys are looking for a way out of this madness. The writing is on the wall.
It works, but needs UX work, documentation and more extensive testing to be appropriate for general use
The article "A Rubyist's Guide to Vite.js"[2] from the author of ViteRuby provides a cool deep dive.
[1]: https://vite-ruby.netlify.app
[2]: https://maximomussini.com/posts/a-rubyist-guide-to-vite-js/
one thing I like in elixir is that the whole language (and thus libraries) are more composable. its easier forme to break and reform functionality from libraries in ways the authors didnt envision. Takes more time to integrate but the end result is way more maintainable.
I think Elixir fans should learn a lesson in being humble...
(I have developed professionally with both Rails and Phoenix and enjoy both.)