Last active
February 26, 2017 23:48
-
-
Save esr360/2377d42605b831a5f6a383cb5584a1ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requirements | |
var sass = require('node-sass'); | |
var fs = require('fs'); | |
var mkdirp = require('mkdirp'); | |
var getDirName = require('path').dirname; | |
function compileSass(options = {}) { | |
// set default options | |
options = Object.assign({ | |
style: 'expanded' | |
}, options); | |
// render the result | |
var result = sass.renderSync({ | |
file: options.src, | |
outputStyle: options.style | |
}); | |
// write the result to file | |
mkdirp(getDirName(options.dest), function(err) { | |
if (err) return cb(err); | |
fs.writeFile(options.dest, result.css); | |
}); | |
// log successful compilation to terminal | |
console.log(' ' + options.dest + ' built.'); | |
}; | |
// Expanded | |
compileSass({ | |
src : 'assets/scss/example.scss', | |
dest: 'dist/css/example.css' | |
}); | |
// Minified | |
compileSass({ | |
src : 'assets/scss/example.scss', | |
dest : 'dist/css/example.min.css', | |
style: 'compressed' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
Object.assign
call here doesn't modify theoptions
object. You'd need to do something like this: