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

Allow node-sass importers to be passed in options. #170

Merged
merged 1 commit into from
Oct 23, 2015
Merged
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
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 @@ -198,7 +204,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 @@ -231,7 +237,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));

// start the actual rendering
if (isSync) {
Expand Down