Skip to content

Instantly share code, notes, and snippets.

@esr360
Last active February 26, 2017 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esr360/2377d42605b831a5f6a383cb5584a1ab to your computer and use it in GitHub Desktop.
Save esr360/2377d42605b831a5f6a383cb5584a1ab to your computer and use it in GitHub Desktop.
// 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'
});
@mAAdhaTTah
Copy link

The Object.assign call here doesn't modify the options object. You'd need to do something like this:

options = Object.assign({
    style: 'expanded'
}, options);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment