SASSy Shopify Workflow
I recently started building a Shopify template for a client and one of the most difficult barriers to getting going was getting myself set up with a sensible workflow. As far as I can tell, there are four main ways to work on a Shopify theme from your desktop:
- Work on the files on your local machine, then zip them up and upload them via the Shopify interface. A poor solution, so much so in fact that it’s not really a solution.
- Use the shopify_theme, a command-line tool on GitHub which will watch a folder and upload files as they are saved. This looks like it could be a good solution but I found it to be a little unstable at times, often silently throwing errors and quitting. “Contribute to it then!” You might shout. To which I will reply “No! Too lazy!”
- Use the Shopify TextMate bundle. I tried this out, but it requires that you use TextMate (I’m a bit of a Sublime Text) and doesn’t seem to have a feature that automatically watches the directory you’re working in, although please correct me if I’m wrong. There seems to be a plugin for Sublime Text too which is a port of the TextMate bundle, but it doesn’t seem to have a huge amount of support. I played with it briefly but it seemed a bit temperamental.
- Use Shopify’s own Desktop Theme Editor which sits and watches the folder you’re working in and uploads files as you save them. It has it’s share of issues though and I’ll address them below.
Shopify & SASS – Not best friends.
While I eventually decided that I would use the Desktop Theme Editor to create my site, it still gave me the runaround – especially when working with SASS.
I have set up an automatic SASS compiler on my computer (CodeKit) which will watch my SASS folder and compile on save. As soon as I started working, I found that the Theme Editor was crashing whenever I tried to save my work. Infuriating so say the least. For some reason, Theme Editor doesn’t like dealing with sass compilers, so with a bit of hunting I found that the thing to do was to put the sass files outside the main theme folder, and configure the compiler to compile the CSS straight into the assets folder. With that problem sorted, I was on my way! …Until I wanted to embed liquid tags in my CSS.
Liquid & SASS
While building the site, I realised that I was going to hit a wall as soon as I wanted to start embedding Shopify’s liquid tags in my CSS. To do this though, you need to start effectively write invalid SASS; tags that should be interpreted by Shopify at runtime. Not only that – your myfile.css files need to be changed to myfile.css.liquid which SASS compilers don’t compile to. Does this really mean having to change the file name every time you save? Fortunately not in the case of CodeKit. It turns out that in CodeKit at least, you can catch the stylesheet saving process and run your own Ruby code. So the following code will rename the file that was just saved for you!
on_stylesheet_saved do |filename| FileUtils.mv(filename, filename + ".liquid") end
That’s that sorted, but what about those pesky liquid tags? Well that’s easily overcome with a bit of SASS magic! (Interpolation)
#{' {{ "established.png" | asset_url }} '}
It’s all a little bit messy but hey, I can live with that until a better solution comes along. I use a Mac, and a lot of these tools are Mac-only so Windows and Linux users, you’re on your own! If you find a better way of working with Shopify Themes get in touch – I’d love to hear it!
view 2 comments