Dropbox download link
Last active
October 17, 2019 14:39
-
-
Save MhdAljuboori/858b580224c3b26011fdd4cc2dd923cb to your computer and use it in GitHub Desktop.
node-sass importer bug
This file contains hidden or 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
// assets/a/a.scss | |
@import "sameFileName"; |
This file contains hidden or 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
// assets/b/anotherFileName.scss | |
@mixin italicFOFO { | |
font-style: italic; | |
} |
This file contains hidden or 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
// assets/b/b.scss | |
@import "sameFileName"; | |
// @import "anotherFileName"; // Works fine |
This file contains hidden or 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 nodeSass = require('node-sass'); | |
var path = require('path'); | |
var fs = require('fs'); | |
var prevMap = {}; | |
var importer = function (request, prev, done) { | |
if (request) { | |
var fileName = null, | |
buff = ""; | |
if (prev == "stdin") { | |
fileName = path.join(__dirname, 'assets'); | |
fileName = path.join(fileName, request); | |
} | |
else { | |
var dirname = path.dirname(prevMap[prev]) // with buff | |
// var dirname = path.dirname(prev); // with fileName | |
fileName = path.join(dirname, request); | |
} | |
if (fileName) { | |
prevMap[request] = fileName; | |
fileName += ".scss"; | |
buff = fs.readFileSync(fileName, 'utf8'); | |
} | |
done({ | |
contents: buff | |
// file: fileName | |
}); | |
} else { | |
done(); | |
} | |
} | |
var source = `@import "a/a"; | |
@import "b/b"; | |
h1 { | |
@include redFOFO; | |
@include italicFOFO; | |
};`; | |
var options = { | |
importer: importer, | |
data: source | |
} | |
nodeSass.render(options, function (error, result) { | |
if (error) { | |
throw error; | |
} | |
else { | |
console.log(result.css.toString()); | |
} | |
}); |
This file contains hidden or 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
// assets/a/sameFileName.scss | |
@mixin redFOFO { | |
color: red | |
} | |
// assets/b/sameFileName.scss | |
@mixin italicFOFO { | |
font-style: italic; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment