Skip to content

Commit

Permalink
feat: 🎸 add scss support for tilde (~) imports
Browse files Browse the repository at this point in the history
✅ Closes: #277
  • Loading branch information
kaisermann committed Nov 17, 2020
1 parent 2a67ac6 commit 5b5c692
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/transformers/scss.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Result } from 'sass';
import type { Importer, Result } from 'sass';

import { Transformer, Processed, Options } from '../types';
import type { Transformer, Processed, Options } from '../types';
import { getIncludePaths, importAny } from '../modules/utils';

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

const tildeImporter: Importer = (url, _prev, done) => {
if (url.startsWith('~')) {
return done({ file: url.slice(1) });
}

return done({ file: url });
};

const transformer: Transformer<Options.Sass> = async ({
content,
filename,
Expand All @@ -44,6 +52,14 @@ const transformer: Transformer<Options.Sass> = async ({
data: content,
};

if (Array.isArray(sassOptions.importer)) {
sassOptions.importer = [tildeImporter, ...sassOptions.importer];
} else if (sassOptions.importer == null) {
sassOptions.importer = [tildeImporter];
} else {
sassOptions.importer = [sassOptions.importer, tildeImporter];
}

// scss errors if passed an empty string
if (sassOptions.data.length === 0) {
return { code: '' };
Expand Down

0 comments on commit 5b5c692

Please sign in to comment.