Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added synchronous support #39

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
31 changes: 21 additions & 10 deletions index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
};