diff --git a/src/utils.js b/src/utils.js index 183ff5f..d4b6f4c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -80,7 +80,6 @@ async function cssnanoMinify( const [[name, code]] = Object.entries(input); const postcssOptions = { - to: name, from: name, ...minimizerOptions.processorOptions, }; @@ -162,9 +161,21 @@ async function cleanCssMinify(input, inputSourceMap, minimizerOptions) { ...minimizerOptions, }).minify({ [name]: { styles: code } }); + const sourceMap = result.sourceMap && result.sourceMap.toJSON(); + + // workaround for source maps on windows + if (sourceMap) { + // eslint-disable-next-line global-require + const isWindowsPathSep = require("path").sep === "\\"; + + sourceMap.sources = sourceMap.sources.map((item) => + isWindowsPathSep ? item.replace(/\\/g, "/") : item + ); + } + return { code: result.styles, - map: result.sourceMap && result.sourceMap.toJSON(), + map: sourceMap, warnings: result.warnings, }; } diff --git a/test/__snapshots__/minify-option.test.js.snap b/test/__snapshots__/minify-option.test.js.snap index 2eb3f53..e0309d9 100644 --- a/test/__snapshots__/minify-option.test.js.snap +++ b/test/__snapshots__/minify-option.test.js.snap @@ -132,6 +132,18 @@ Error: minimizer function doesn't return the 'code' property or result is not a exports[`"minify" option should work throw an error if minimizer function doesn't return: warning 1`] = `Array []`; +exports[`"minify" option should work with "CssMinimizerPlugin.cleanCssMinify" minifier and generate source maps #2: assets 1`] = ` +Object { + "foo/foo.css": "body{font-weight:700}body{color:red}body a{text-align:center} +/*# sourceMappingURL=foo.css.map*/", + "foo/foo.css.map": "{\\"version\\":3,\\"file\\":\\"foo/foo.css\\",\\"mappings\\":\\"AAAA,KACE,YAAa,ICCf,KACE,MAAO,IACP,OACE,WAAY\\",\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"names\\":[],\\"sourceRoot\\":\\"\\"}", +} +`; + +exports[`"minify" option should work with "CssMinimizerPlugin.cleanCssMinify" minifier and generate source maps #2: error 1`] = `Array []`; + +exports[`"minify" option should work with "CssMinimizerPlugin.cleanCssMinify" minifier and generate source maps #2: warning 1`] = `Array []`; + exports[`"minify" option should work with "CssMinimizerPlugin.cleanCssMinify" minifier and generate source maps: assets 1`] = ` Object { "foo.css": "body{color:red}a{color:#00f} @@ -154,7 +166,19 @@ exports[`"minify" option should work with "CssMinimizerPlugin.cleanCssMinify" mi exports[`"minify" option should work with "CssMinimizerPlugin.cleanCssMinify" minifier: warning 1`] = `Array []`; -exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" and generate source maps: assets 1`] = ` +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier and generate source maps #2: assets 1`] = ` +Object { + "foo/foo.css": "body{color:red;font-weight:700}body a{text-align:center} +/*# sourceMappingURL=foo.css.map*/", + "foo/foo.css.map": "{\\"version\\":3,\\"file\\":\\"foo/foo.css\\",\\"mappings\\":\\"AAAA,KCGE,SAAU,CDFV,eCCF,CAEE,OACE,iBAIJ\\",\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"names\\":[],\\"sourceRoot\\":\\"\\"}", +} +`; + +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier and generate source maps #2: error 1`] = `Array []`; + +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier and generate source maps #2: warning 1`] = `Array []`; + +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier and generate source maps: assets 1`] = ` Object { "foo.css": "body{color:red;font-weight:700}body a{text-align:center} /*# sourceMappingURL=foo.css.map*/", @@ -162,13 +186,23 @@ Object { } `; -exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" and generate source maps: error 1`] = `Array []`; +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier and generate source maps: error 1`] = `Array []`; + +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier and generate source maps: warning 1`] = `Array []`; + +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier and parser option as "String": entry.js.map 1`] = `"{\\"version\\":3,\\"file\\":\\"entry.js\\",\\"mappings\\":\\";;UAAA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;ACNO\\",\\"sources\\":[\\"webpack:///webpack/bootstrap\\",\\"webpack:///webpack/runtime/define property getters\\",\\"webpack:///webpack/runtime/hasOwnProperty shorthand\\",\\"webpack:///webpack/runtime/make namespace object\\",\\"webpack:///./sugarss.js\\"],\\"sourcesContent\\":[\\"// The require scope\\\\nvar __webpack_require__ = {};\\\\n\\\\n\\",\\"// define getter functions for harmony exports\\\\n__webpack_require__.d = (exports, definition) => {\\\\n\\\\tfor(var key in definition) {\\\\n\\\\t\\\\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\\\\n\\\\t\\\\t\\\\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\\\\n\\\\t\\\\t}\\\\n\\\\t}\\\\n};\\",\\"__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\\",\\"// define __esModule on exports\\\\n__webpack_require__.r = (exports) => {\\\\n\\\\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\\\\n\\\\t\\\\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\\\\n\\\\t}\\\\n\\\\tObject.defineProperty(exports, '__esModule', { value: true });\\\\n};\\",\\"export const foo = 'foo';\\\\n\\"],\\"names\\":[],\\"sourceRoot\\":\\"\\"}"`; -exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" and generate source maps: warning 1`] = `Array []`; +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier and parser option as "String": index.sss 1`] = `"a{color:#000}"`; + +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier: assets 1`] = ` +Object { + "foo.css": "body{color:red;font-weight:700}body a{text-align:center}", +} +`; -exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" and parser option as "String": entry.js.map 1`] = `"{\\"version\\":3,\\"file\\":\\"entry.js\\",\\"mappings\\":\\";;UAAA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;ACNO\\",\\"sources\\":[\\"webpack:///webpack/bootstrap\\",\\"webpack:///webpack/runtime/define property getters\\",\\"webpack:///webpack/runtime/hasOwnProperty shorthand\\",\\"webpack:///webpack/runtime/make namespace object\\",\\"webpack:///./sugarss.js\\"],\\"sourcesContent\\":[\\"// The require scope\\\\nvar __webpack_require__ = {};\\\\n\\\\n\\",\\"// define getter functions for harmony exports\\\\n__webpack_require__.d = (exports, definition) => {\\\\n\\\\tfor(var key in definition) {\\\\n\\\\t\\\\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\\\\n\\\\t\\\\t\\\\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\\\\n\\\\t\\\\t}\\\\n\\\\t}\\\\n};\\",\\"__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))\\",\\"// define __esModule on exports\\\\n__webpack_require__.r = (exports) => {\\\\n\\\\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\\\\n\\\\t\\\\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\\\\n\\\\t}\\\\n\\\\tObject.defineProperty(exports, '__esModule', { value: true });\\\\n};\\",\\"export const foo = 'foo';\\\\n\\"],\\"names\\":[],\\"sourceRoot\\":\\"\\"}"`; +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier: error 1`] = `Array []`; -exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" and parser option as "String": index.sss 1`] = `"a{color:#000}"`; +exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify" minifier: warning 1`] = `Array []`; exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify", "CssMinimizerPlugin.cssoMinify" and "CssMinimizerPlugin.cleanCssMinify" minifiers and generate source maps: assets 1`] = ` Object { @@ -192,27 +226,29 @@ exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify", " exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify", "CssMinimizerPlugin.cssoMinify" and "CssMinimizerPlugin.cleanCssMinify" minifiers: warning 1`] = `Array []`; -exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify": assets 1`] = ` +exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier and generate source map: assets 1`] = ` Object { - "foo.css": "body{color:red;font-weight:700}body a{text-align:center}", + "foo.css": "body{font-weight:700;color:red}body a{text-align:center} +/*# sourceMappingURL=foo.css.map*/", + "foo.css.map": "{\\"version\\":3,\\"file\\":\\"foo.css\\",\\"mappings\\":\\"AAAA,I,CACE,e,CCEA,S,CACA,M,CACE,iB\\",\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"names\\":[],\\"sourceRoot\\":\\"\\"}", } `; -exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify": error 1`] = `Array []`; +exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier and generate source map: error 1`] = `Array []`; -exports[`"minify" option should work with "CssMinimizerPlugin.cssnanoMinify": warning 1`] = `Array []`; +exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier and generate source map: warning 1`] = `Array []`; -exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier and generate source map: assets 1`] = ` +exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier and generate source maps #2: assets 1`] = ` Object { - "foo.css": "body{font-weight:700;color:red}body a{text-align:center} + "foo/foo.css": "body{font-weight:700;color:red}body a{text-align:center} /*# sourceMappingURL=foo.css.map*/", - "foo.css.map": "{\\"version\\":3,\\"file\\":\\"foo.css\\",\\"mappings\\":\\"AAAA,I,CACE,e,CCEA,S,CACA,M,CACE,iB\\",\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"names\\":[],\\"sourceRoot\\":\\"\\"}", + "foo/foo.css.map": "{\\"version\\":3,\\"file\\":\\"foo/foo.css\\",\\"mappings\\":\\"AAAA,I,CACE,e,CCEA,S,CACA,M,CACE,iB\\",\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"names\\":[],\\"sourceRoot\\":\\"\\"}", } `; -exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier and generate source map: error 1`] = `Array []`; +exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier and generate source maps #2: error 1`] = `Array []`; -exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier and generate source map: warning 1`] = `Array []`; +exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier and generate source maps #2: warning 1`] = `Array []`; exports[`"minify" option should work with "CssMinimizerPlugin.cssoMinify" minifier: assets 1`] = ` Object { @@ -242,6 +278,19 @@ Unexpected \\"calc(\\"", ] `; +exports[`"minify" option should work with "CssMinimizerPlugin.esbuildMinify" minifier and generate source maps #2: assets 1`] = ` +Object { + "foo/foo.css": "body{font-weight:bold}body{color:red}body a{text-align:center} + +/*# sourceMappingURL=foo.css.map*/", + "foo/foo.css.map": "{\\"version\\":3,\\"file\\":\\"foo/foo.css\\",\\"mappings\\":\\"AAAA,KACE,iBCCF,KACE,UACA,OACE\\",\\"sources\\":[\\"webpack:///./sourcemap/bar.scss\\",\\"webpack:///./sourcemap/foo.scss\\"],\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"names\\":[],\\"sourceRoot\\":\\"\\"}", +} +`; + +exports[`"minify" option should work with "CssMinimizerPlugin.esbuildMinify" minifier and generate source maps #2: error 1`] = `Array []`; + +exports[`"minify" option should work with "CssMinimizerPlugin.esbuildMinify" minifier and generate source maps #2: warning 1`] = `Array []`; + exports[`"minify" option should work with "CssMinimizerPlugin.esbuildMinify" minifier and generate source maps: assets 1`] = ` Object { "foo.css": "body{color:red}a{color:#00f} diff --git a/test/__snapshots__/sourceMap-option.test.js.snap b/test/__snapshots__/sourceMap-option.test.js.snap index eb417f9..364a5f4 100644 --- a/test/__snapshots__/sourceMap-option.test.js.snap +++ b/test/__snapshots__/sourceMap-option.test.js.snap @@ -19,12 +19,14 @@ Object { "dist/entry2.css.map": { "version": 3, "file": "dist/entry2.css", - "mappings": "AAAA,KAKE,SAAU,CAJV,eACF,CAMA,OACE,iBACF", + "mappings": "AAAA,KCGE,SAAU,CDFV,eCCF,CAIA,OACE,iBAGF", "sources": [ - "webpack:///entry2.css" + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.css" ], "sourcesContent": [ - "body {\\n font-weight: bold;\\n}\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}\\n" + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}" ], "names": [], "sourceRoot": "" @@ -49,12 +51,14 @@ Object { "sourcemaps/entry.css.map": { "version": 3, "file": "dist/entry.css", - "mappings": "AAAA,KAKE,SAAU,CAJV,eACF,CAKA,OACE,iBACF", + "mappings": "AAAA,KCGE,SAAU,CDFV,eCCF,CAEE,OACE,iBAIJ", "sources": [ - "webpack:///entry.css" + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.scss" ], "sourcesContent": [ - "body {\\n font-weight: bold;\\n}\\n\\nbody {\\n color: red;\\n}\\nbody a {\\n text-align: center;\\n}\\n" + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}" ], "names": [], "sourceRoot": "" @@ -62,12 +66,14 @@ Object { "sourcemaps/entry2.css.map": { "version": 3, "file": "dist/entry2.css", - "mappings": "AAAA,KAKE,SAAU,CAJV,eACF,CAMA,OACE,iBACF", + "mappings": "AAAA,KCGE,SAAU,CDFV,eCCF,CAIA,OACE,iBAGF", "sources": [ - "webpack:///entry2.css" + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.css" ], "sourcesContent": [ - "body {\\n font-weight: bold;\\n}\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}\\n" + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}" ], "names": [], "sourceRoot": "" diff --git a/test/minify-option.test.js b/test/minify-option.test.js index 6bc0111..f514df0 100644 --- a/test/minify-option.test.js +++ b/test/minify-option.test.js @@ -250,7 +250,7 @@ describe('"minify" option', () => { expect(getWarnings(stats)).toMatchSnapshot("warning"); }); - it('should work with "CssMinimizerPlugin.cssnanoMinify"', async () => { + it('should work with "CssMinimizerPlugin.cssnanoMinify" minifier', async () => { const compiler = getCompiler({ entry: { foo: `${__dirname}/fixtures/sourcemap/foo.scss`, @@ -285,7 +285,7 @@ describe('"minify" option', () => { expect(getWarnings(stats)).toMatchSnapshot("warning"); }); - it('should work with "CssMinimizerPlugin.cssnanoMinify" and generate source maps', async () => { + it('should work with "CssMinimizerPlugin.cssnanoMinify" minifier and generate source maps', async () => { const compiler = getCompiler({ devtool: "source-map", entry: { @@ -321,7 +321,49 @@ describe('"minify" option', () => { expect(getWarnings(stats)).toMatchSnapshot("warning"); }); - it('should work with "CssMinimizerPlugin.cssnanoMinify" and parser option as "String"', async () => { + it('should work with "CssMinimizerPlugin.cssnanoMinify" minifier and generate source maps #2', async () => { + const compiler = getCompiler({ + devtool: "source-map", + entry: { + foo: `${__dirname}/fixtures/sourcemap/foo.scss`, + }, + module: { + rules: [ + { + test: /.s?css$/i, + use: [ + MiniCssExtractPlugin.loader, + { loader: "css-loader", options: { sourceMap: true } }, + { loader: "sass-loader", options: { sourceMap: true } }, + ], + }, + ], + }, + plugins: [ + new MiniCssExtractPlugin({ + filename: "foo/[name].css", + chunkFilename: "foo/[id].[name].css", + }), + ], + }); + + new CssMinimizerPlugin({ + minimizerOptions: { + preset: "default", + }, + minify: [CssMinimizerPlugin.cssnanoMinify], + }).apply(compiler); + + const stats = await compile(compiler); + + expect(readAssets(compiler, stats, /\.css(\.map)?$/)).toMatchSnapshot( + "assets" + ); + expect(getErrors(stats)).toMatchSnapshot("error"); + expect(getWarnings(stats)).toMatchSnapshot("warning"); + }); + + it('should work with "CssMinimizerPlugin.cssnanoMinify" minifier and parser option as "String"', async () => { const compiler = getCompiler({ devtool: "source-map", entry: { @@ -430,6 +472,45 @@ describe('"minify" option', () => { expect(getWarnings(stats)).toMatchSnapshot("warning"); }); + it('should work with "CssMinimizerPlugin.cssoMinify" minifier and generate source maps #2', async () => { + const compiler = getCompiler({ + devtool: "source-map", + entry: { + foo: `${__dirname}/fixtures/sourcemap/foo.scss`, + }, + module: { + rules: [ + { + test: /.s?css$/i, + use: [ + MiniCssExtractPlugin.loader, + { loader: "css-loader", options: { sourceMap: true } }, + { loader: "sass-loader", options: { sourceMap: true } }, + ], + }, + ], + }, + plugins: [ + new MiniCssExtractPlugin({ + filename: "foo/[name].css", + chunkFilename: "foo/[id].[name].css", + }), + ], + }); + + new CssMinimizerPlugin({ + minify: [CssMinimizerPlugin.cssoMinify], + }).apply(compiler); + + const stats = await compile(compiler); + + expect(readAssets(compiler, stats, /\.css(\.map)?$/)).toMatchSnapshot( + "assets" + ); + expect(getErrors(stats)).toMatchSnapshot("error"); + expect(getWarnings(stats)).toMatchSnapshot("warning"); + }); + it('should work with "CssMinimizerPlugin.cleanCssMinify" minifier', async () => { const compiler = getCompiler({ entry: { @@ -471,6 +552,45 @@ describe('"minify" option', () => { expect(getWarnings(stats)).toMatchSnapshot("warning"); }); + it('should work with "CssMinimizerPlugin.cleanCssMinify" minifier and generate source maps #2', async () => { + const compiler = getCompiler({ + devtool: "source-map", + entry: { + foo: `${__dirname}/fixtures/sourcemap/foo.scss`, + }, + module: { + rules: [ + { + test: /.s?css$/i, + use: [ + MiniCssExtractPlugin.loader, + { loader: "css-loader", options: { sourceMap: true } }, + { loader: "sass-loader", options: { sourceMap: true } }, + ], + }, + ], + }, + plugins: [ + new MiniCssExtractPlugin({ + filename: "foo/[name].css", + chunkFilename: "foo/[id].[name].css", + }), + ], + }); + + new CssMinimizerPlugin({ + minify: [CssMinimizerPlugin.cleanCssMinify], + }).apply(compiler); + + const stats = await compile(compiler); + + expect(readAssets(compiler, stats, /\.css(\.map)?$/)).toMatchSnapshot( + "assets" + ); + expect(getErrors(stats)).toMatchSnapshot("error"); + expect(getWarnings(stats)).toMatchSnapshot("warning"); + }); + it('should work with "CssMinimizerPlugin.esbuildMinify" minifier', async () => { const compiler = getCompiler({ entry: { @@ -555,6 +675,45 @@ describe('"minify" option', () => { expect(getWarnings(stats)).toMatchSnapshot("warning"); }); + it('should work with "CssMinimizerPlugin.esbuildMinify" minifier and generate source maps #2', async () => { + const compiler = getCompiler({ + devtool: "source-map", + entry: { + foo: `${__dirname}/fixtures/sourcemap/foo.scss`, + }, + module: { + rules: [ + { + test: /.s?css$/i, + use: [ + MiniCssExtractPlugin.loader, + { loader: "css-loader", options: { sourceMap: true } }, + { loader: "sass-loader", options: { sourceMap: true } }, + ], + }, + ], + }, + plugins: [ + new MiniCssExtractPlugin({ + filename: "foo/[name].css", + chunkFilename: "foo/[id].[name].css", + }), + ], + }); + + new CssMinimizerPlugin({ + minify: [CssMinimizerPlugin.esbuildMinify], + }).apply(compiler); + + const stats = await compile(compiler); + + expect(readAssets(compiler, stats, /\.css(\.map)?$/)).toMatchSnapshot( + "assets" + ); + expect(getErrors(stats)).toMatchSnapshot("error"); + expect(getWarnings(stats)).toMatchSnapshot("warning"); + }); + it('should work with "CssMinimizerPlugin.cssnanoMinify", "CssMinimizerPlugin.cssoMinify" and "CssMinimizerPlugin.cleanCssMinify" minifiers', async () => { const compiler = getCompiler({ entry: {