Skip to content

Commit 539032a

Browse files
author
Ives van Hoorne
committed
Add support for ~ resolving in sass
Fixes codesandbox#594
1 parent 25f4583 commit 539032a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/app/src/sandbox/eval/transpilers/sass/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class SassTranspiler extends WorkerTranspiler {
1313
this.cacheable = false;
1414
}
1515

16-
doTranspilation(code: string, loaderContext: LoaderContext) {
16+
doTranspilation(
17+
code: string,
18+
loaderContext: LoaderContext
19+
): Promise<{ transpiledCode: string }> {
1720
const extension =
1821
typeof loaderContext.options.indentedSyntax === 'undefined'
1922
? 'scss'
@@ -22,6 +25,11 @@ class SassTranspiler extends WorkerTranspiler {
2225
const customPath = loaderContext.path + '.' + extension;
2326

2427
return new Promise((resolve, reject) => {
28+
if (code === '' || code == null) {
29+
resolve({ transpiledCode: '' });
30+
return;
31+
}
32+
2533
this.queueTask(
2634
{
2735
code,

packages/app/src/sandbox/eval/transpilers/sass/sass-worker.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ const getExistingPath = async (fs, p) => {
5151
return existedFile;
5252
};
5353

54-
const resolveSass = (fs, p, path) =>
55-
new Promise((r, reject) => {
54+
const resolveSass = (fs, p, path) => {
55+
const usedPath = p.startsWith('~') ? p.replace('~', '/node_modules/') : p;
56+
57+
return new Promise((r, reject) => {
5658
resolve(
57-
p,
59+
usedPath,
5860
{
5961
filename: path,
6062
extensions: ['.scss', '.css', '.sass'],
@@ -101,6 +103,7 @@ const resolveSass = (fs, p, path) =>
101103
}
102104
);
103105
});
106+
};
104107

105108
function initializeBrowserFS() {
106109
return new Promise(res => {

0 commit comments

Comments
 (0)