Skip to content

Instantly share code, notes, and snippets.

@superfein
Forked from derekmorash/gulpfile.js
Created February 13, 2023 07:31
Show Gist options
  • Save superfein/2017ca16997a79c9def4072452361d7d to your computer and use it in GitHub Desktop.
Save superfein/2017ca16997a79c9def4072452361d7d to your computer and use it in GitHub Desktop.
Gulp task to compile Shopify Liquid tags in SASS with Autoprefixer
var gulp = require('gulp');
var sass = require('gulp-sass');
var replace = require('gulp-replace');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
gulp.task('compilesass', function() {
// root SASS file (contains all your includes)
return gulp.src('./sass/style.scss')
// compile SASS to CSS
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
// add vendor prefixes
.pipe(autoprefixer())
// change the file name to be a liquid file
.pipe(concat('style.css.liquid'))
// remove the extra set of quotations used for escaping the liquid string
.pipe(replace('"{{', '{{'))
.pipe(replace('}}"', '}}'))
// save the file to the theme assets directory
.pipe(gulp.dest('./assets/'));
});
gulp.task('default', function() {
// watch all SASS (.scss) files
gulp.watch(['./sass/**/*.scss'], ['compilesass']);
});
.classname {
// note the extra set of double quotes
background-image: url(#{'"{{ \'awesome-hero-image.jpg\' | asset_url }}"'});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment