I’m curious about peoples thoughts about this, especially of @chrismccord.
In my project I have brunch and 2 other javascript build systems as well as a dozen libraries I specifically call, it is… unwieldy.
I started looking at other popular javascript build systems recently (as shown by a past recent thread). Grunt was horrible, don’t touch it, Gulp is good, kind of like Brunch (it has watcher, reloaders, hot-reloaders, etc…), it is completely async (if the supporting libraries are, like brunch, which elm’s brunch plugin is not for one example), it is a bit more verbose but not overly so, however it is significantly more capable, looks like it can handle all the things that brunch cannot that I’ve needed. Webpack can kind of do the same things as gulp, though it takes significantly more code to do things except the most simple of cases, which ‘can’ be shorter than gulp, but not really, I’m not seeing the point in it.
However, I ran across an article: https://www.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/
I completely forgot about another build tool that comes with phoenix, npm itself!
With some simple npm packages I got watchers, reloaders, concurrent compiling, can use all the base packages that the 50-thousand gulp/webpack/brunch plugins use under the hood but directly, etc…
So I spent this morning disabling brunch just commented its like in my dev.exs file, it ‘works’, mostly (it has bugs that necessitate two-recompiles often), and rewriting everything I did in brunch and the other systems in just npm itself, following that article, the result is that it is shorter, compiles faster (mostly due to being able to run the stuff the other systems absolutely had to do synchronously but concurrently, and no multiple rebuilds), and I say it is more readable.
So… why not just use npm for the build system of the assets in Phoenix? Replace in the dev.exs template this:
node: ["node_modules/brunch/bin/brunch", "watch", "--stdin", cd: Path.expand("../", __DIR__)]
To become this:
node: ["npm", "run", "watch", cd: Path.expand("../", __DIR__)]
That will call the ‘watch’ task, which in my package.json (you can define tasks outside of the package.json in your own *.js files if you want too) is defined as:
"watch": "parallelshell \"npm run watch:javascript\" \"'npm run watch:scss\" \"npm run watch:webcomponents\" \"npm run watch:elm\" \"npm run watch:bucklescript\" \"npm run watch:copy\"'",
And those all run concurrently, and inside those are build systems that also run concurrently. It is actually surprisingly nice. I think that I’ll run like this for a while and maybe entirely remove all the other build stuff here later.
And yes, it is *SO*FREAKING*NICE* that I do not have to double-save my files just to get brunch to notice an update (with 50 seconds in-between because the elm-brunch plugin sucks and freezes everything while it spends its 50 seconds to compile the elm stuff), and the important stuff (I.E. not the 50-second long elm compiles) are compiled about instantly so my iteration time just dropped like a rock in a vacuum high-gravity environment. ^.^
So yeah, with this change and with the recent symlink windows fix for phoenix (run as admin in dev mode…) iteration time has become fantastic again! ^.^
But yes, any thoughts as to removing brunch from the phoenix new template generator entirely and just using npm itself? It reduces dependencies, its faster, its shorter, and its less confusing then the odd brunch config (which though nice once you understand it, is definitely confusing at first).