diff --git a/src/utils.js b/src/utils.js index 9271532..0b2e9a5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -277,6 +277,11 @@ async function getDependencies( return; } + // Avoid search nested imports in .css + if (path.extname(dependency) === ".css") { + return; + } + loaderContext.addDependency(dependency); dependenciesOfDependencies.push( diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 61732bc..a789355 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -588,6 +588,15 @@ exports[`loader resolve with webpack if stylus can't find it: errors 1`] = `Arra exports[`loader resolve with webpack if stylus can't find it: warnings 1`] = `Array []`; +exports[`loader resolves broken css with webpack but does not import it: css 1`] = ` +"@import \\"css-keyframe.css\\"; +" +`; + +exports[`loader resolves broken css with webpack but does not import it: errors 1`] = `Array []`; + +exports[`loader resolves broken css with webpack but does not import it: warnings 1`] = `Array []`; + exports[`loader resolves css with webpack but does not import it: css 1`] = ` "@import \\"css.css\\"; " diff --git a/test/fixtures/css-keyframe.css b/test/fixtures/css-keyframe.css new file mode 100644 index 0000000..d65a3ae --- /dev/null +++ b/test/fixtures/css-keyframe.css @@ -0,0 +1,4 @@ +.imported-css { + border: 5px; +} +@keyframes cdk-text-field-autofill-start{/*!*/} diff --git a/test/fixtures/import-webpack-css-keyframe.styl b/test/fixtures/import-webpack-css-keyframe.styl new file mode 100644 index 0000000..b697b9e --- /dev/null +++ b/test/fixtures/import-webpack-css-keyframe.styl @@ -0,0 +1 @@ +@import "css-keyframe.css"; diff --git a/test/loader.test.js b/test/loader.test.js index 5452840..c9f82f2 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -509,6 +509,19 @@ describe("loader", () => { expect(getErrors(stats)).toMatchSnapshot("errors"); }); + it("resolves broken css with webpack but does not import it", async () => { + const testId = "./import-webpack-css-keyframe.styl"; + const compiler = getCompiler(testId); + const stats = await compile(compiler); + const codeFromBundle = getCodeFromBundle(stats, compiler); + const codeFromStylus = await getCodeFromStylus(testId); + + expect(codeFromBundle.css).toBe(codeFromStylus.css); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + }); + it('should work "use" option', async () => { function plugin() { return (style) => {