Skip to content

Instantly share code, notes, and snippets.

@callumacrae
Created November 23, 2015 13:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callumacrae/09de2b8294339d6a6785 to your computer and use it in GitHub Desktop.
Save callumacrae/09de2b8294339d6a6785 to your computer and use it in GitHub Desktop.
var path = require('path');
var findup = require('findup-sync');
var cache = {};
function sassNpmImporter(url, prev, done) {
// Fall back to old URL
var newUrl = url;
try {
if (cache[url]) {
newUrl = cache[url];
return;
}
if (url[0] === '.' || url.indexOf('/') !== -1) {
return;
}
var modulePath = findup(path.join('node_modules', url), {
cwd: path.dirname(prev),
nocase: true
});
var moduleJson = require(path.join(modulePath, 'package.json'));
newUrl = path.join(modulePath, moduleJson.mainSass);
} catch (e) {
// Ignore error
} finally {
cache[url] = newUrl;
done({ file: newUrl });
}
}
module.exports = sassNpmImporter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment