diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 0e2d71fb..2602c814 --- a/README.md +++ b/README.md @@ -42,6 +42,14 @@ module.exports = { Then you only need to write: `require("./file.scss")`. See [`node-sass`](https://github.com/andrew/node-sass) for the available options. +### async/sync + +By default, all processing is done **asynchronously** unless the `sync` parameter is passed + +``` javascript +var css = require("!raw!sass?sync!./file.scss"); +``` + ## Install `npm install sass-loader` diff --git a/index.js b/index.js old mode 100644 new mode 100755 index be2ca18e..fceda367 --- a/index.js +++ b/index.js @@ -5,11 +5,15 @@ var sassGraph = require('sass-graph'); module.exports = function (content) { this.cacheable(); - var callback = this.async(); var opt = utils.parseQuery(this.query); opt.data = content; + var callback = function() {}; + if (opt.sync !== true) { + callback = this.async(); + } + // skip empty files, otherwise it will stop webpack, see issue #21 if (opt.data.trim() === '') { return callback(null, content); @@ -39,16 +43,23 @@ module.exports = function (content) { } }.bind(this); - opt.success = function (css) { + if (opt.sync === true) { + var css = sass.renderSync(opt); markDependencies(); - callback(null, css); - }.bind(this); + return css; + } + else { + opt.success = function (css) { + markDependencies(); + callback(null, css); + }.bind(this); - opt.error = function (err) { - markDependencies(); - this.emitError(err); - callback(err); - }.bind(this); + opt.error = function (err) { + markDependencies(); + this.emitError(err); + callback(err); + }.bind(this); - sass.render(opt); + sass.render(opt); + } };