Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Fix sass imports #75

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
18 changes: 14 additions & 4 deletions src/css/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export default class SassCompiler extends CompilerBase {
sourceMapRoot: filePath,
});

// not a valid option
delete opts.paths;

let result = await new Promise((res,rej) => {
sass.compile(sourceCode, opts, (r) => {
if (r.status !== 0) {
Expand Down Expand Up @@ -161,10 +164,8 @@ export default class SassCompiler extends CompilerBase {
done();
return;
} else {
// sass.js works in the '/sass/' directory
const cleanedRequestPath = request.resolved.replace(/^\/sass\//, '');
for (let includePath of includePaths) {
const filePath = path.resolve(includePath, cleanedRequestPath);
const filePathGenerator = getFilepathsForVariation(includePaths, request);
for (let filePath of filePathGenerator) {
let variations = sass.getPathVariations(filePath);

file = variations
Expand Down Expand Up @@ -227,3 +228,12 @@ export default class SassCompiler extends CompilerBase {
return "4.1.1";
}
}

function *getFilepathsForVariation(includePaths, request) {
const resolved = request.resolved.replace(/^\/sass\//, '');
yield resolved;
const current = request.current;
for (let includePath of includePaths) {
yield path.resolve(includePath, current);
}
}