diff --git a/src/minify.js b/src/minify.js index bde0915..9bffb17 100644 --- a/src/minify.js +++ b/src/minify.js @@ -49,7 +49,7 @@ const minify = async (options) => { return { code: result.css, - map: result.map, + map: result.map && result.map.toString(), warnings: warningsToString(result.warnings()), }; }; diff --git a/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 b/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 index fb5a807..308f73d 100644 --- a/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 +++ b/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 @@ -69,6 +69,92 @@ exports[`when applied with "sourceMap" option should work with SourceMapDevToolP exports[`when applied with "sourceMap" option should work with SourceMapDevToolPlugin plugin): warnings 1`] = `Array []`; +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: assets 1`] = ` +Object { + "entry.css": "body{font-weight:700;color:red}body a{text-align:center} +/*# sourceMappingURL=entry.css.map*/", + "entry.css.map": { + "version": 3, + "sources": [ + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.scss" + ], + "names": [], + "mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB", + "file": "entry.css", + "sourcesContent": [ + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}" + ], + "sourceRoot": "" +}, + "entry2.css": "body{font-weight:700;color:red}body a{text-align:center} +/*# sourceMappingURL=entry2.css.map*/", + "entry2.css.map": { + "version": 3, + "sources": [ + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.css" + ], + "names": [], + "mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB", + "file": "entry2.css", + "sourcesContent": [ + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}" + ], + "sourceRoot": "" +}, +} +`; + +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: errors 1`] = `Array []`; + +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: warnings 1`] = `Array []`; + +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: assets 1`] = ` +Object { + "entry.css": "body{font-weight:700;color:red}body a{text-align:center} +/*# sourceMappingURL=entry.css.map*/", + "entry.css.map": { + "version": 3, + "sources": [ + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.scss" + ], + "names": [], + "mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB", + "file": "entry.css", + "sourcesContent": [ + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}" + ], + "sourceRoot": "" +}, + "entry2.css": "body{font-weight:700;color:red}body a{text-align:center} +/*# sourceMappingURL=entry2.css.map*/", + "entry2.css.map": { + "version": 3, + "sources": [ + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.css" + ], + "names": [], + "mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB", + "file": "entry2.css", + "sourcesContent": [ + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}" + ], + "sourceRoot": "" +}, +} +`; + +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: errors 1`] = `Array []`; + +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: warnings 1`] = `Array []`; + exports[`when applied with "sourceMap" option should work with the "devtool" option: assets 1`] = ` Object { "entry.css": "body{font-weight:700;color:red}body a{text-align:center} diff --git a/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 b/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 index 48a445b..bef69bc 100644 --- a/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 +++ b/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 @@ -69,6 +69,92 @@ exports[`when applied with "sourceMap" option should work with SourceMapDevToolP exports[`when applied with "sourceMap" option should work with SourceMapDevToolPlugin plugin): warnings 1`] = `Array []`; +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: assets 1`] = ` +Object { + "entry.css": "body{font-weight:700;color:red}body a{text-align:center} +/*# sourceMappingURL=entry.css.map*/", + "entry.css.map": { + "version": 3, + "sources": [ + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.scss" + ], + "names": [], + "mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB", + "file": "entry.css", + "sourcesContent": [ + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}" + ], + "sourceRoot": "" +}, + "entry2.css": "body{font-weight:700;color:red}body a{text-align:center} +/*# sourceMappingURL=entry2.css.map*/", + "entry2.css.map": { + "version": 3, + "sources": [ + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.css" + ], + "names": [], + "mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB", + "file": "entry2.css", + "sourcesContent": [ + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}" + ], + "sourceRoot": "" +}, +} +`; + +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: errors 1`] = `Array []`; + +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: warnings 1`] = `Array []`; + +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: assets 1`] = ` +Object { + "entry.css": "body{font-weight:700;color:red}body a{text-align:center} +/*# sourceMappingURL=entry.css.map*/", + "entry.css.map": { + "version": 3, + "sources": [ + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.scss" + ], + "names": [], + "mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB", + "file": "entry.css", + "sourcesContent": [ + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}" + ], + "sourceRoot": "" +}, + "entry2.css": "body{font-weight:700;color:red}body a{text-align:center} +/*# sourceMappingURL=entry2.css.map*/", + "entry2.css.map": { + "version": 3, + "sources": [ + "webpack:///./sourcemap/bar.scss", + "webpack:///./sourcemap/foo.css" + ], + "names": [], + "mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB", + "file": "entry2.css", + "sourcesContent": [ + "body {\\n font-weight: bold;\\n}", + "@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}" + ], + "sourceRoot": "" +}, +} +`; + +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: errors 1`] = `Array []`; + +exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: warnings 1`] = `Array []`; + exports[`when applied with "sourceMap" option should work with the "devtool" option: assets 1`] = ` Object { "entry.css": "body{font-weight:700;color:red}body a{text-align:center} diff --git a/test/__snapshots__/worker.test.js.snap.webpack4 b/test/__snapshots__/worker.test.js.snap.webpack4 index 24006ff..62d9fc4 100644 --- a/test/__snapshots__/worker.test.js.snap.webpack4 +++ b/test/__snapshots__/worker.test.js.snap.webpack4 @@ -8,43 +8,11 @@ Array [ exports[`worker should minify css: css 1`] = `".foo{color:red}.bar{color:coral}"`; -exports[`worker should minify css: map 1`] = ` -Object { - "file": "entry.css", - "mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY", - "names": Array [], - "sources": Array [ - "foo.css", - "entry.css", - ], - "sourcesContent": Array [ - ".foo{color:red;}", - ".foo{color:red;} -.bar{color:coral;}", - ], - "version": 3, -} -`; +exports[`worker should minify css: map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"foo.css\\",\\"entry.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KAAK,SAAA,CCCL,KAAK,WAAY\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\".foo{color:red;}\\",\\".foo{color:red;}\\\\n.bar{color:coral;}\\"]}"`; exports[`worker should work inputSourceMap as prev: css 1`] = `".foo{color:red}.bar{color:coral}"`; -exports[`worker should work inputSourceMap as prev: map 1`] = ` -Object { - "file": "entry.css", - "mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY", - "names": Array [], - "sources": Array [ - "foo.css", - "entry.css", - ], - "sourcesContent": Array [ - ".foo{color:red;}", - ".foo{color:red;} -.bar{color:coral;}", - ], - "version": 3, -} -`; +exports[`worker should work inputSourceMap as prev: map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"foo.css\\",\\"entry.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KAAK,SAAA,CCCL,KAAK,WAAY\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\".foo{color:red;}\\",\\".foo{color:red;}\\\\n.bar{color:coral;}\\"]}"`; exports[`worker should work options.minify function: css 1`] = `".minify {};"`; diff --git a/test/__snapshots__/worker.test.js.snap.webpack5 b/test/__snapshots__/worker.test.js.snap.webpack5 index 24006ff..62d9fc4 100644 --- a/test/__snapshots__/worker.test.js.snap.webpack5 +++ b/test/__snapshots__/worker.test.js.snap.webpack5 @@ -8,43 +8,11 @@ Array [ exports[`worker should minify css: css 1`] = `".foo{color:red}.bar{color:coral}"`; -exports[`worker should minify css: map 1`] = ` -Object { - "file": "entry.css", - "mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY", - "names": Array [], - "sources": Array [ - "foo.css", - "entry.css", - ], - "sourcesContent": Array [ - ".foo{color:red;}", - ".foo{color:red;} -.bar{color:coral;}", - ], - "version": 3, -} -`; +exports[`worker should minify css: map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"foo.css\\",\\"entry.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KAAK,SAAA,CCCL,KAAK,WAAY\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\".foo{color:red;}\\",\\".foo{color:red;}\\\\n.bar{color:coral;}\\"]}"`; exports[`worker should work inputSourceMap as prev: css 1`] = `".foo{color:red}.bar{color:coral}"`; -exports[`worker should work inputSourceMap as prev: map 1`] = ` -Object { - "file": "entry.css", - "mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY", - "names": Array [], - "sources": Array [ - "foo.css", - "entry.css", - ], - "sourcesContent": Array [ - ".foo{color:red;}", - ".foo{color:red;} -.bar{color:coral;}", - ], - "version": 3, -} -`; +exports[`worker should work inputSourceMap as prev: map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"foo.css\\",\\"entry.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KAAK,SAAA,CCCL,KAAK,WAAY\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\".foo{color:red;}\\",\\".foo{color:red;}\\\\n.bar{color:coral;}\\"]}"`; exports[`worker should work options.minify function: css 1`] = `".minify {};"`; diff --git a/test/sourceMap-option.test.js b/test/sourceMap-option.test.js index 5110322..e2bebb0 100644 --- a/test/sourceMap-option.test.js +++ b/test/sourceMap-option.test.js @@ -70,6 +70,38 @@ describe('when applied with "sourceMap" option', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); }); + it('should work with the "devtool" option and the "parallel" option with "false" value', async () => { + const compiler = getCompiler(baseConfig); + + new CssMinimizerPlugin({ + parallel: false, + }).apply(compiler); + + const stats = await compile(compiler); + + expect(readAssets(compiler, stats, /\.css(\.map)?$/)).toMatchSnapshot( + 'assets' + ); + expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + }); + + it('should work with the "devtool" option and the "parallel" option with "true" value', async () => { + const compiler = getCompiler(baseConfig); + + new CssMinimizerPlugin({ + parallel: true, + }).apply(compiler); + + const stats = await compile(compiler); + + expect(readAssets(compiler, stats, /\.css(\.map)?$/)).toMatchSnapshot( + 'assets' + ); + expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + }); + it('should work with the "true" value', async () => { const config = Object.assign(baseConfig, { module: {