Compiling Assets

Postified on November 27th, 2019

Up until the Statamic 3 beta we had been happily committing our SASS and JavaScript source files without worrying about how to package everything up for end users. We asked alpha testers to compile the assets on their own machines. Not too much to ask for a small set of experienced and vested developers. But we knew we'd have to solve this workflow sooner or later.

Now that the Statamic 3 Beta is open, sooner or later became now. When you install Statamic everything should be ready to go. Part of that is making sure that the compiled assets are in the right spot. The only way we knew to do this was to compile production-ready assets locally and track them in Git. I had asked around and it seemed that this was just how it is done.

Yes. We compile before release.

— Holiday Hemp (@davidhemphill) November 22, 2019

Yeah same with ignition. It holds the compiled assets - otherwise it wouldn’t work out of the box

— Marcel Pociot 🎆 (@marcelpociot) November 23, 2019


So, we did just that. But good grief Charlie Brown it felt 9 flavors of icky.

We run npm run watch locally while we develop, which leaves us with a lot of unstaged, compiled files we had to be careful to not accidentally commit. If we wanted had to commit them, we would cancel the watcher, recompile using npm run prod, and then commit. It was tedious.

It only took 24 hours for me get frustrated enough to roll up my sleeves and find a better way. Hell hath no fury like an annoyed developer.

So I created a better way

I threw together a fairly simple Composer plugin that will download a zip file from a provided URL and extract it whenever your package is installed or updated.

Github Actions lets us automate the creation of the zip.

I created a workflow that gets triggered whenever we tag a new version of Statamic. The assets get compiled, zipped up, and added to the release.

Now whenever you install that version of Statamic through Composer, it'll grab the zip from the corresponding release with the pre-compiled assets like magic straight from Hogwarts School of Witchcraft and Wizardry.

Github Action

Give it a try

If you've installed Statamic in the past few days, thanks for being early testers! Going forward you will need to change the version constraint in your composer.json.

"require": {
    "statamic/cms": "3.0.*@beta"
}

Change dev-master to 3.0.*@beta then run composer update statamic/cms --with-dependencies and you should be ready to roll.

If you're a package developer, feel free to try out composer-dist-plugin and let us know if it works for you too.

Jason Varga
Jason Varga, Lead Deveoper @ Statamic
Lead Developer

Copyright 2019 ⚔️ Statamic