Compiling Magento 2 static assets offline

  • You can’t
  • I think the Magento config and compilation process are so coupled it’s not worth bothering

What’s the standard with Magento 1?

The current pipeline with Magento 1.x I’ve seen is either

  • $ vim styles.css
    $ git add ./
    $ git commit -m “Yolo”

or (slightly better)

  • $ vim scss/core/_box.scss
    $ git add ./ -p
    $ git commit -m “Yolo”
    $ sassc scss/styles.scss > css/styles.css

Regardless, the assets are generated without any knowledge of the stack (IMO this is good)

So, why does Magento 2 require the database?

As best as I can tell, with some super short investigation, it checks store configuration values such as whether the Less should be minified. This relies on being able to query what stores exist, as well as configuration values that are normally in core_config_data.

This isn’t really a “bad” thing — It might be a valid use case for a developer / merchant to just “yolo” in some theme on a per store basis and compile it through the GUI. However, if I were to discover someone I knew doing this, I would probably have a quiet discussion with them about the benefits of

  • Not modifying things in prod
  • Not making the Magento stack worry about asset generation — Something that historically, it’s not particularly good at
  • Using a build process to compile the application, and
  • Immutable applications

So, what’s the solution?

If I were to suggest a solution to the Magento developers, it would be to not interface with the Magneto stack when developing the static assets. If you need to, output some sort of configuration to file, and read from that.

In the end, I’m probably just going to dump the Magento build process as much as possible. I dislike the idea the application has to worry about compiling its own resources — I’ll go back to the way of constructing themes I know and understand.

Boring Stuff

Think I’m wrong? Please, correct me! If nothing else, one of us will leave here with more knowledge.

--

--

See https://www.andrewhowden.com/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store