Skip to content

Commit 055c88e

Browse files
committed
Merge pull request #170 from Updater/importers
Allow `node-sass` importers to be passed in options.
2 parents a6cc46f + 18ca85f commit 055c88e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ module.exports = function (content) {
3737
var isSync = typeof callback !== 'function';
3838
var self = this;
3939
var resourcePath = this.resourcePath;
40+
var query = utils.parseQuery(this.query);
4041
var result;
4142
var opt;
4243

44+
// Allow passing "programmable objects" (e.g. importers) via custom `this.options` field.
45+
// http://webpack.github.io/docs/how-to-write-a-loader.html#programmable-objects-as-query-option
46+
var configKey = query.config || 'sassLoader';
47+
var configOptions = this.options[configKey] || {};
48+
4349
/**
4450
* Enhances the sass error with additional information about what actually went wrong.
4551
*
@@ -204,7 +210,7 @@ module.exports = function (content) {
204210

205211
this.cacheable();
206212

207-
opt = utils.parseQuery(this.query);
213+
opt = query;
208214
opt.data = content;
209215

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

240-
opt.importer = getWebpackImporter();
246+
// Allow passing custom importers to `node-sass`. Accepts `Function` or an array of `Function`s.
247+
opt.importer = []
248+
.concat(configOptions.importer || [])
249+
.concat(getWebpackImporter());
250+
251+
// `node-sass` uses `includePaths` to resolve `@import` paths. Append the currently processed file.
252+
opt.includePaths = (opt.includePaths || [])
253+
.concat(path.dirname(resourcePath));
241254

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

0 commit comments

Comments
 (0)