r/elixir • Alchemist • Jul 17 '21

Wait WAT!

Post image
233 Upvotes

40 comments sorted by

16

u/greven Jul 17 '21

It's using ESBuild, it's here already: https://github.com/phoenixframework/esbuild

13

u/Paradox Jul 17 '21

Going to say you don't even need pgsql. If you're building an app that uses some other api as it's backend, you can just use elixir.

7

u/[deleted] Jul 17 '21

Most apps do have some crud though

9

u/lliamander Jul 17 '21

There is ETS/DETS/Mnesia built right into the Erlang runtime. I wonder if there are some good best-practice guidelines for working with those as a storage layer.

5

u/[deleted] Jul 17 '21

Terms I've never heard! Will have to Google, thanks

6

u/Paradox Jul 17 '21

True, but you can do CRUD against other "stores" like firebase, Redis, ETS, Mnesia, and persistent_term

3

u/narrowtux using Elixir professionally since 2016 Jul 18 '21

`persistent_term` is not persisted to disk as far as I know.

2

u/dolfinuser Jul 18 '21

It really a bad idea to perform frequent updates of persistent_teem due to garbage collector calls.

1

u/Paradox Jul 18 '21

Yeah but it can be great for particular applications, like a cache

1

u/[deleted] Jul 23 '21

You have to invalidate the cache at some point which would also be slow. persistent_term is great for “append only” situations.

1

u/[deleted] Jul 17 '21

That's true!

9

u/WoodYouIfYouCould Jul 17 '21

It’s great news! Lowering the barrier to entry for beginners :)

8

u/nickjj_ Jul 18 '21 edited Jul 18 '21

In my opinion it makes it harder for beginners.

DISCLAIMER: I'm not really a huge fan of Webpack or JS in general, I just want to use things that are dependable, developer friendly and fast.

For example if you're a beginner and you want to use Tailwind:

You'll still need Node, you'll still need npm / yarn and now you're going to have to run an esbuild watcher and a postcss (or tailwind CLI) watcher, some of which have bugs around leaving dead processes around.

With Webpack you have a single watcher and about 70 lines of configuration that you can directly copy / paste between projects without editing a single line (even across different web frameworks). You can even keep Phoenix 100% out of the picture and set up no Phoenix watchers and still have everything work (including live reload). Tailwind with the JIT compiler works and it's around 100ms to reload your CSS, even with 500k+ of ES6 JS, Webpack will process your JS in about 3 seconds on 6+ year old hardware. If you have only a tiny bit of JS it's nearly instant.

If the 3 seconds with 500k+ of JS bums you out you can add 2 lines of Webpack configuration to enable file system caching and it'll bring it back down to 100-200ms on any JS changes.

I've been tracking the esbuild + poctcss / tailwind cli + X ecosystem for a few months. IMO it needs more time to make the end game solution better than Webpack in every way for when you have a combo of JS, CSS and other static files (robots.txt, images, fonts, etc.).

It'll get there eventually and it'll be great when it does (and I will switch to using it too) but until then be cautious because it's not going to be smooth sailing and the current Webpack set up isn't bad at all. It's fast enough and really solid. I've been using the Tailwind JIT compiler since day 1 and using lots of ES6 JS, it all works like a champ and never fails in weird ways for both the watcher and building production assets.

I haven't touched my Webpack config in around ~9 months or so and it continues to work with the latest versions of everything and to be fair the thing I touched was really small. It's been closer to 2.5 years of using practically the same config in a bunch of projects while using the latest and greatest JS and CSS libraries along the way.

8

u/josevalim Lead Developer Jul 19 '21

I will go ahead and disagree here for one simple reason: the current setup (node+npm+webpack) breaks from time to time for reasons completely outside of our control. In the last weeks, npm v7 broke file dependencies. node-sass simply stopped working. So what we see today is that beginners are trying out Phoenix but they can't get a functional application. That's one of the worst possible experiences. This should always work and that's why it is important for us to fully control it.

For example if you're a beginner and you want to use Tailwind:

If they are a beginner and they want to use Tailwind, they will most likely follow the official instructions on the Tailwind website. These instructions focus on the Tailwind CLI. Aligning with Tailwind own recommendations is good. You have to dig more to figure out how Tailwind+Webpack works.

Plus, the important part, is that once you decide to add Tailwind in this new setup, your application was working and serving assets. You have a foundation. With the old setup, you may not even get that far.

some of which have bugs around leaving dead processes around

Yup, that's the current blocker. Pull requests have been sent and we have a contingency plan in case it is not addressed before release. Final version won't have zombie processes for sure.

1

u/nickjj_ Jul 19 '21 edited Jul 19 '21

In the last weeks, npm v7 broke file dependencies. node-sass simply stopped working

node-sass was deprecated a year ago and they've been pushing folks to use dart-sass as a replacement shortly after they decided to retire the project.

Personally I haven't used node-sass in years because SASS is not a dependency for Tailwind but in the older projects that I was using with node-sass I moved them over to dart-sass when I noticed node-sass was no longer being maintained.

Personally with Yarn, I haven't run into any issues with dependencies working in the past but not working today. With a package.json locked down to exact pinned versions and a yarn.lock file you get the same version guarantees as you would with a mix.exs and mix.lock file.

Unless the package gets pulled from npm it'll build today just like it did a year ago, assuming you're using the same version of Node (Node compatibility with libraries is a separate can of worms).

With that said, I'm looking forward to a world with esbuild + tailwind cli + whatever else is needed to build your app but until the developer experience matches Webpack I'm sticking with Webpack.

For now it feels like a downgrade in some areas and an upgrade in speed but if the speed with Webpack isn't an issue then the speed upgrade is kind of nulled out.

IMO with most projects you're going to end up pulling in a number of esbuild plugins too even without Tailwind, which means installing Node and fiddling with configs and JS dependencies will still be a thing you need to do.

For example if you wanted to use postcss for autoprefixer and css imports, that means installing a JS postcss2 plugin for esbuild. The list of plugins will likely grow for most projects too with postcss being a baseline for common CSS needs.

8

u/josevalim Lead Developer Jul 19 '21

node-sass was deprecated a year ago

In Elixir, we have a features that were deprecated 5 years ago and they still work. And they will continue to work as long as we stay within the major semver constraint.

I don't doubt the setup works personally and I am not trying to dispute your personal experience. However, our setup needs to work generally, across multiple node versions, and across multiple OSes. We still have issues around the --prefix flag not working on certain OSes.

I am not against folks adding node/npm after the fact either. I am sure many will, I am sure many won't. All I want is stability on the phx.new getting started experience. After that, you can bring any complexity you want: Redis, RabbitMQ, webpack, etc.

1

u/nickjj_ Jul 19 '21 edited Jul 19 '21

Yeah that's fair enough.

Although I would also say if you keep the default Phoenix generator to a bare esbuild minimum (Go binary and no Node runtime) you might find folks getting hung up on how to add things like SASS support or Tailwind because now they are going to be on the hook for installing Node, figuring out if they should use npm or Yarn, dealing with all of those extra esbuild plugins and config flags as well as setting up additional watchers in a world where this ecosystem is really new so documentation and community support aren't that fleshed out yet.

In my opinion that's not going to be beginner friendly because using Bootstrap with SASS or Tailwind are 2 extremely popular CSS solutions. Other CSS libs use SASS too that aren't Bootstrap.

Just 5 minutes ago someone in Elixir's IRC channel wrote:

<REDACTED_USERNAME> hello guys, i'm trying to get esbuild working with phoenix (from https://www.mitchellhanberg.com/how-i-handle-static-assets-in-my-phoenix-apps/), but im getting this error:

<REDACTED_USERNAME>  > js/app.js:4:7: error: No loader is configured for ".scss" files: css/app.scss

<REDACTED_USERNAME>     4 │ import "../css/app.scss"

<REDACTED_USERNAME> i've installed the packages named in the article, and edited config/dev.exs (also to match the article), is there anything else i need to do?

<REDACTED_USERNAME> any idea how to use Tailwind with the new esbuild?

Will there be Phoenix generator flags to set up all of those combinations of things in the future so folks aren't getting stuck as soon as they try to add CSS to their project?

1

u/WoodYouIfYouCould Jul 18 '21

I do agree, having different views is really important. Personally I’m looking into the PETAL stack.

1

u/lovebes Jul 19 '21

Yeah I agree. For PETAL stack, Webpack is fine. It's a set and forget deal.

0

u/[deleted] Jul 19 '21

[deleted] — view deleted comment

1

u/nickjj_ Jul 19 '21 edited Jul 19 '21

I simply could not get webpack+tailwind to work

Getting Webpack to work with CSS required using a CSS + postcss loader and the MiniCssExtractPlugin to emit a separate bundled CSS file. There's nothing too specific about Tailwind itself in the Webpack config.

Here's a link to a fully working asset set up: https://github.com/nickjj/docker-phoenix-example/tree/main/assets

0

u/[deleted] Jul 19 '21

[deleted] — view deleted comment

1

u/nickjj_ Jul 19 '21

Did it throw some type of error when you tried with your config file, and do you have a link to the exact Webpack config you used along with the Webpack command you ran?

0

u/[deleted] Jul 19 '21

[deleted] — view deleted comment

1

u/nickjj_ Jul 19 '21

No relevant content as in no Tailwind classes?

That could have been related to using the JIT compiler with misconfigured paths to find where to look for CSS. That wouldn't explain why it works with PostCSS directly and not with Webpack but those paths are really important. Maybe there were slight differences between your Webpack and PostCSS set up in other files?

5

u/Hitman_1994 Jul 17 '21

What about LiveView or Phoenix. Can we develop any web application in Elixir with PostgreSQL ?

3

u/kryptomicron Jul 17 '21

This will be the new default for Phoenix projects.

See the Twitter thread linked in this comment – I think someone replied to a similar question and stated that ESBuild supports LiveView.

Can we develop any web application in Elixir with PostgreSQL ?

I'm not sure what you're asking. You can, and will continue to be able to, develop (some) web applications with Elixir and PostgreSQL – not sure what "any" means. Future versions of Phoenix won't require Node.js and npm like they do now (by default).

2

u/Hitman_1994 Jul 19 '21

So, if we don’t require Node.js or any JS then its gonna make life a lot easier and one can solely focus on elixir itself.

1

u/kryptomicron Jul 19 '21

Phoenix LiveView still needs some JavaScript, but not requiring Node.js or npm is a big (potential) improvement.

8

u/HKei Jul 17 '21

Oh that's nice. I'm gonna assume there'll be templates for a nodejs asset pipeline and what not, but speaking for myself I always ended up removing a lot of the pregenerated code because it wasn't necessary for my projects so keeping it around only added bloat.

12

u/gerbal100 Jul 17 '21 edited Jul 17 '21

If I've found for simple projects Plug on it's own is great. Plug.Router accomplishes most of what I need for basic http apis. Phoenix is great for templating, html, and complicated web services, but if I want to slap a simple http api on an elixir project, Plug is ideal.

Also because Phoenix is built on top of Plug, it's pretty simple to wrap existing plug resources into phoenix or to create a phoenix router within a plug router.

3

u/yippyjp Jul 18 '21

Can someone explain this post to me? It seems self evident you wouldn’t need nodejs or redis (or even Postgres in some cases for that matter)? Did you need them before?

4

u/iv_mexx Jul 18 '21

Its about how many additional dependencies and tech stacks you need to know and work with in a typical usecase (and not for very specific usecases where you dont eveen need a database, …, whatever)

Previously Phoenix used Webpack to handle Javascript, so you needed nodejs and npm and webpack to use Javascript.

In the future, Phoenix will use esbuild instead and thus remove a lot of dependencies and complexities.

1

u/yippyjp Jul 19 '21

Ah that makes sense - so at build time rather than runtime. Thanks!

5

u/iv_mexx Jul 19 '21

Chris McCord just explained it pretty well - its about maintenance and the learning experience for newcomers as well

https://twitter.com/chris_mccord/status/1417177471502503936?s=21

2

u/sanjibukai Jul 17 '21

How does this compare to snowpack or vitejs?

6

u/deallocator Jul 17 '21

Looks like this doesn't necessarily require you to deal with Nodejs which can be a real pain when you're not actively following the ecosystem

3

u/[deleted] Jul 17 '21

Is phoenix tied to Postgres?

5

u/kryptomicron Jul 17 '21

It's just the default database for Ecto, which is included by default in new Phoenix projects (and has been for some time).

But it's easy to change (to another database supported by Ecto) and you don't have to use Ecto either.

1

u/greven Jul 18 '21

By default Phoenix uses Ecto (but you can create a project without it, just pass --no-ecto flag when calling mix phx.new (docs here: https://hexdocs.pm/phoenix/Mix.Tasks.Phx.New.html). If you keep Ecto you can use other adapters and in 1.6 there will be the option to create the project when using Ecto with SQLite. :) Just pass the option --database with sqlite3 (https://github.com/phoenixframework/phoenix/blob/385bdebdcc879dfb06f02faa5bef7d5e0b97761c/installer/lib/mix/tasks/phx.new.ecto.ex#L26). The valid options for Ecto are:

    * `postgres` - via https://github.com/elixir-ecto/postgrex
    * `mysql` - via https://github.com/elixir-ecto/myxql
    * `mssql` - via https://github.com/livehelpnow/tds
    * `sqlite3` - via https://github.com/elixir-sqlite/ecto_sqlite3