Skip to content

Commit 7bfefda

Browse files
fix: allow to import CSS using @use with css extension
1 parent 115b9a0 commit 7bfefda

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,9 @@ function getPossibleRequests(
379379
// - imports that have media queries.
380380
//
381381
// The `node-sass` package sends `@import` ending on `.css` to importer, it is bug, so we skip resolve
382+
// Also sass outputs as is `@import "style.css"`, but `@use "style.css"` should include CSS content
382383
if (extension === ".css") {
383-
return [];
384+
return fromImport ? [] : [url];
384385
}
385386

386387
const dirname = path.dirname(request);

test/loader.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,25 @@ describe("loader", () => {
18581858
await close(compiler);
18591859
});
18601860

1861+
it(`should work when "@use" with CSS extension ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
1862+
const testId = getTestId("use-css", syntax);
1863+
const options = {
1864+
implementation,
1865+
api,
1866+
};
1867+
const compiler = getCompiler(testId, { loader: { options } });
1868+
const stats = await compile(compiler);
1869+
const codeFromBundle = getCodeFromBundle(stats, compiler);
1870+
const codeFromSass = await getCodeFromSass(testId, options);
1871+
1872+
expect(codeFromBundle.css).toBe(codeFromSass.css);
1873+
expect(codeFromBundle.css).toMatchSnapshot("css");
1874+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
1875+
expect(getErrors(stats)).toMatchSnapshot("errors");
1876+
1877+
await close(compiler);
1878+
});
1879+
18611880
it(`should work when "@use" with the "bootstrap-sass" package, directly import ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
18621881
const testId = getTestId("use-bootstrap-sass", syntax);
18631882
const options = {

test/sass/use-css.sass

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@use 'css/some-css-module.css'

test/scss/use-css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@use 'css/some-css-module.css';

0 commit comments

Comments
 (0)