-
-
Save callumacrae/09de2b8294339d6a6785 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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