hubertlepicki

hubertlepicki

I’m updating app from Phoenix 1.3 to Phoenix 1.4 (rc.2). Everything went smooth with exception of assets compilation.

At 1.3, we actually been still using Brunch. It’s working well and the problems appear only on update to Phoenix 1.4.

The main issue I am facing is that phoenix.js file, that is being loaded using package.json from ../deps/node_modules/phoenix, is now compiled but keeps using ES6 syntax. For example, it’s using “const something” instead of “var something”. If you open this file phoenix/priv/static/phoenix.js at 93ad4c2932a8cd2c28095c8c82d1966729c7bc76 · phoenixframework/phoenix · GitHub and search for "const " you’ll see what I mean.

This was not the case before, as you can see with 1.3 version of phoenix.js file here: https://github.com/phoenixframework/phoenix/blob/v1.3.4/priv/static/phoenix.js

The file is now also minified, which is redundant as I am running uglifier anyway on the resulting app.js, or - rather - I would like to run uglifier on the app.js file but it crashes precisely because of it containing ES6 syntax now.

I am terrible at the JavaScript build tools to be fair, so figured I may as well ask - is there a way to use Phoenix 1.4 with Brunch, or am I basically forced to upgrade to webpack?

Showing Posts 1 to 10

LostKobrakai

LostKobrakai

On slack there has also been some discussion around that from someone using phoenix.js by directly linking to it in his html, which also doesn’t work well depending on the browser. I’m not sure, but wasn’t there a way to include both and via the package.json declare which file is ES5 and which is a ES6 source file? I’ve seen lot’s of examples even for webpack, which don’t compile anything in node_modules to save on compile time.

hubertlepicki

hubertlepicki OP

As ignorant as I am, all the other libraries we are using are already transpiled, and brunch does not have to compile them. phoenix.js seems odd here :confused:

peerreynders

peerreynders

(Haven’t tried 1.4 yet).

Short answer: Yes. (Longer answer: If you really want to get into the weeds with Brunch there likely is a path through it. Maybe just act as if “phoenix.js” is one of your not-precompiled JS files and have it push it through Babel)

I suspect the underlying issue is the Babel presets being used to generate phoenix.js. More recent “default” Babel configurations aren’t sticking strictly to ES5 (unnecessarily slow) but are in fact moving towards “the part of ES2015 as it is supported by most browsers”.

When Babel can’t find a browserslist somewhere it assumes:

> 0.5%, last 2 versions, Firefox ESR, not dead .

Included browsers e.g. IE11 but not below.

hubertlepicki

hubertlepicki OP

I think you are right. The core of my problem is that Uglify-JS 3.x does not support “const” syntax. And this syntax is supported by majority of browsers already, so it makes sense to compile it this way.

So, my issue seems not to be related at all to brunch, which in fact works, but uglify-js-brunch.

When uglify-js-brunch is being removed, project compiles properly. Now I just need to find a replacement for it because 6MB app.js file is not something I really want :smiley:

hubertlepicki

hubertlepicki OP

I ended up replacing uglify-js with terser which is a maintained fork, supporting ES6: https://www.npmjs.com/package/terser

chrismccord

chrismccord

Creator of Phoenix

The compiled phoenix.js bundle is supposed to be es5. We switched internally to webpack for building phoenix.js, and I assumed it would be es5 output, but JS is never that easy. I’ll take a look and see what we can do. The upgrade to webpack is purely user choice and shouldn’t be required. If brunch is working for you then by all means you should stay on it :slight_smile:

hubertlepicki

hubertlepicki OP

Ha, so I found a bug.

peerreynders

peerreynders

Not necessarily. I’m sure Chris is strongly motivated to not to cause any undue effort for pre-1.4 adopters but … essentially using Brunch with 1.4 (and above) is a similar position to using pre-1.4 Phoenix with anything but Brunch. The default JS tools aren’t really a core concern of Phoenix - they are merely supplied as a convenience.

If this is a Babel issue one has to remember that Babel does not target language specifications but rather feature sets as they are provided by various browsers and Node. UMD modules are starting to fall out of favour and the code therein is largely becoming ES2015.

How to write and build JS libraries in 2018

It’s basically becoming more and more difficult to pre-compile all the various permutations that people may want, so transpiling of vendor code may become a user responsibility again.

So when you are finally ready to leave Brunch behind you may not want to blindly adopt webpack 4 but spend some time to find something that suits you - because more than likely you’ll be spending some significant time with it.

davydog187

davydog187

It was just a simple misconfiguration. I’ve addressed it here: Fix Phoenix.js ES5 output, upgrade webpack by davydog187 · Pull Request #3126 · phoenixframework/phoenix · GitHub

You can pull in Phoenix master for a working build.

hubertlepicki

hubertlepicki OP

I think phoenix.js is still pretty simple and bare bones. So, ideally, you could just copy it over and load without any transpiler, compiler or bundler and it could work for you. And this is fine, I have done that recently with simple admin panel and it is great. I think if we do not have to, we should not throw away possibility to support these simple use cases.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews