diff --git a/src/runtime/cssWithMappingToString.js b/src/runtime/cssWithMappingToString.js index 2a7fda69..e6c7603f 100644 --- a/src/runtime/cssWithMappingToString.js +++ b/src/runtime/cssWithMappingToString.js @@ -1,6 +1,10 @@ module.exports = function cssWithMappingToString(item) { const [, content, , cssMapping] = item; + if (!cssMapping) { + return content; + } + if (typeof btoa === "function") { // eslint-disable-next-line no-undef const base64 = btoa( diff --git a/test/runtime/__snapshots__/api.test.js.snap b/test/runtime/__snapshots__/api.test.js.snap index 3304a234..03a55291 100644 --- a/test/runtime/__snapshots__/api.test.js.snap +++ b/test/runtime/__snapshots__/api.test.js.snap @@ -18,6 +18,8 @@ exports[`api should toString with a source map without "sourceRoot" 1`] = ` /*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC5zY3NzIiwic291cmNlcyI6WyIuL3BhdGgvdG8vdGVzdC5zY3NzIl0sIm1hcHBpbmdzIjoiQUFBQTsifQ== */" `; +exports[`api should toString with a source map without map 1`] = `"@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');"`; + exports[`api should toString with media query 1`] = `"body { b: 2; }body { c: 3; }body { b: 2; }@media print {body { b: 2; }}@media print {body { d: 4; }}@media screen {body { a: 1; }}"`; exports[`api should toString with source mapping 1`] = ` diff --git a/test/runtime/api.test.js b/test/runtime/api.test.js index 7c1bbaf7..337ddeec 100644 --- a/test/runtime/api.test.js +++ b/test/runtime/api.test.js @@ -145,6 +145,18 @@ describe("api", () => { expect(m.toString()).toMatchSnapshot(); }); + // https://github.com/webpack-contrib/css-loader/issues/1322 + it("should toString with a source map without map", () => { + const m = api(cssWithMappingToString); + + m.push([ + 1, + "@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');", + ]); + + expect(m.toString()).toMatchSnapshot(); + }); + it("should import modules with dedupe", () => { const m = api((i) => i[1]); diff --git a/test/sourceMap-option.test.js b/test/sourceMap-option.test.js index 635e7fc4..3d0c695a 100644 --- a/test/sourceMap-option.test.js +++ b/test/sourceMap-option.test.js @@ -501,8 +501,8 @@ describe('"sourceMap" option', () => { expect(chunkName).toBe( webpack.version[0] === "5" - ? "main.6480a869998e0b381c90.bundle.js" - : "main.19efc497c5c37fc5e355.bundle.js" + ? "main.b67984bbf9dd298785fb.bundle.js" + : "main.a64c858ed0f4c1ed322c.bundle.js" ); expect( getModuleSource("fixtures/source-map/basic.css", stats)