Compiling Magento 2 static assets offline

Tl, Dr (Too Long, Didn’t Read)

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

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)

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

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.

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




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