Skip to content

Commit 61e15a2

Browse files
committed
feat: 🎸 add scss support for tilde (~) imports
✅ Closes: #277
1 parent 2a67ac6 commit 61e15a2

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

‎src/transformers/scss.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Result } from 'sass';
1+
import type { Importer, Result } from 'sass';
22

3-
import { Transformer, Processed, Options } from '../types';
3+
import type { Transformer, Processed, Options } from '../types';
44
import { getIncludePaths, importAny } from '../modules/utils';
55

66
let sass: Options.Sass['implementation'];
@@ -19,6 +19,14 @@ function getResultForResolve(result: Result): ResolveResult {
1919
};
2020
}
2121

22+
const tildeImporter: Importer = (url, _prev, done) => {
23+
if (url.startsWith('~')) {
24+
return done({ file: url.slice(1) });
25+
}
26+
27+
return done({ file: url });
28+
};
29+
2230
const transformer: Transformer<Options.Sass> = async ({
2331
content,
2432
filename,
@@ -44,6 +52,14 @@ const transformer: Transformer<Options.Sass> = async ({
4452
data: content,
4553
};
4654

55+
if (Array.isArray(sassOptions.importer)) {
56+
sassOptions.importer.push(tildeImporter);
57+
} else if (sassOptions.importer == null) {
58+
sassOptions.importer = [tildeImporter];
59+
} else {
60+
sassOptions.importer = [sassOptions.importer, tildeImporter];
61+
}
62+
4763
// scss errors if passed an empty string
4864
if (sassOptions.data.length === 0) {
4965
return { code: '' };

0 commit comments

Comments
 (0)