Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ class CssMinimizerPlugin {
innerSourceMap,
true,
);
} else if (item.code) {
} else if (typeof item.code !== "undefined" && item.code !== null) {
output.source = new RawSource(item.code);
}
}
Expand Down
15 changes: 0 additions & 15 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ const notSettled = Symbol("not-settled");
* @returns {Promise<T[]>} A promise that fulfills to an array of the results
*/
function throttleAll(limit, tasks) {
if (!Number.isInteger(limit) || limit < 1) {
throw new TypeError(
`Expected \`limit\` to be a finite number > 0, got \`${limit}\` (${typeof limit})`,
);
}

if (
!Array.isArray(tasks) ||
!tasks.every((task) => typeof task === "function")
) {
throw new TypeError(
"Expected `tasks` to be a list of functions returning a promise",
);
}

return new Promise((resolve, reject) => {
const result = Array.from({ length: tasks.length }).fill(notSettled);
const entries = tasks.entries();
Expand Down
28 changes: 28 additions & 0 deletions test/CssMinimizerPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,34 @@ describe("CssMinimizerPlugin", () => {
).toMatchSnapshot();
});

it("should work", async () => {
const compiler = getCompiler({
entry: path.join(__dirname, "fixtures", "entry.js"),
});

new CssMinimizerPlugin().apply(compiler);

const stats = await compile(compiler);

expect(readAssets(compiler, stats, /\.css$/)).toMatchSnapshot("assets");
expect(getErrors(stats)).toMatchSnapshot("errors");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
});

it("should work with empty files", async () => {
const compiler = getCompiler({
entry: path.join(__dirname, "fixtures", "empty.js"),
});

new CssMinimizerPlugin().apply(compiler);

const stats = await compile(compiler);

expect(readAssets(compiler, stats, /\.css$/)).toMatchSnapshot("assets");
expect(getErrors(stats)).toMatchSnapshot("errors");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
});

it("should build error", () => {
const compiler = getCompiler({
entry: {
Expand Down
20 changes: 20 additions & 0 deletions test/__snapshots__/CssMinimizerPlugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ exports[`CssMinimizerPlugin should work with child compilation: errors 1`] = `[]

exports[`CssMinimizerPlugin should work with child compilation: warnings 1`] = `[]`;

exports[`CssMinimizerPlugin should work with empty files: assets 1`] = `
{
"main.css": "",
}
`;

exports[`CssMinimizerPlugin should work with empty files: errors 1`] = `[]`;

exports[`CssMinimizerPlugin should work with empty files: warnings 1`] = `[]`;

exports[`CssMinimizerPlugin should work with source map and use memory cache when the "cache" option is "true" and the asset has been changed: assets 1`] = `
{
"foo.css": "body{color:red}a{color:blue}
Expand Down Expand Up @@ -396,6 +406,16 @@ exports[`CssMinimizerPlugin should work with warnings and use memory cache when
]
`;

exports[`CssMinimizerPlugin should work: assets 1`] = `
{
"main.css": "body{color:red}a{color:blue}",
}
`;

exports[`CssMinimizerPlugin should work: errors 1`] = `[]`;

exports[`CssMinimizerPlugin should work: warnings 1`] = `[]`;

exports[`CssMinimizerPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: assets 1`] = `
{
"one.css": ".minify {};",
Expand Down
10 changes: 1 addition & 9 deletions test/__snapshots__/minify-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,7 @@ exports[`"minify" option should work with "csso" minifier: warning 1`] = `[]`;

exports[`"minify" option should work with empty code: assets 1`] = `
{
"foo.css": "body {
color: red;
}
a {
color: blue;
}

/*# sourceMappingURL=foo.css.map*/",
"foo.css.map": "{"version":3,"file":"foo.css","mappings":"AAAA;EACE,UAAU;AACZ;AACA;EACE,WAAW;AACb,C","sources":["webpack:///./foo.css"],"sourcesContent":["body {\\n color: red;\\n}\\na {\\n color: blue;\\n}"],"names":[],"sourceRoot":""}",
"foo.css": "",
}
`;

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/empty.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* comment */
1 change: 1 addition & 0 deletions test/fixtures/empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./empty.css";
2 changes: 1 addition & 1 deletion test/helpers/getCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import webpack from "webpack";
* @param {import("webpack").Configuration} config Webpack configuration
* @returns {import("webpack").Compiler} Webpack compiler
*/
export default function getCompiler(config) {
export default function getCompiler(config = {}) {
const compiler = webpack({
mode: "development",
devtool: config.devtool || false,
Expand Down