Skip to content

Commit

Permalink
Merge pull request #170 from Updater/importers
Browse files Browse the repository at this point in the history
Allow `node-sass` importers to be passed in options.
  • Loading branch information
jhnns committed Oct 23, 2015
2 parents a6cc46f + 18ca85f commit 055c88e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ module.exports = function (content) {
var isSync = typeof callback !== 'function';
var self = this;
var resourcePath = this.resourcePath;
var query = utils.parseQuery(this.query);
var result;
var opt;

// Allow passing "programmable objects" (e.g. importers) via custom `this.options` field.
// http://webpack.github.io/docs/how-to-write-a-loader.html#programmable-objects-as-query-option
var configKey = query.config || 'sassLoader';
var configOptions = this.options[configKey] || {};

/**
* Enhances the sass error with additional information about what actually went wrong.
*
Expand Down Expand Up @@ -204,7 +210,7 @@ module.exports = function (content) {

this.cacheable();

opt = utils.parseQuery(this.query);
opt = query;
opt.data = content;

// Skip empty files, otherwise it will stop webpack, see issue #21
Expand Down Expand Up @@ -237,7 +243,14 @@ module.exports = function (content) {
// indentedSyntax is a boolean flag
opt.indentedSyntax = Boolean(opt.indentedSyntax);

opt.importer = getWebpackImporter();
// Allow passing custom importers to `node-sass`. Accepts `Function` or an array of `Function`s.
opt.importer = []
.concat(configOptions.importer || [])
.concat(getWebpackImporter());

// `node-sass` uses `includePaths` to resolve `@import` paths. Append the currently processed file.
opt.includePaths = (opt.includePaths || [])
.concat(path.dirname(resourcePath));

// functions can't be set in query, load from sassLoader section in webpack options
if (this.options.sassLoader) {
Expand Down

0 comments on commit 055c88e

Please sign in to comment.