Skip to content

Commit

Permalink
dep: upgrade webpack css mini plugin and lightningcss (#11877)
Browse files Browse the repository at this point in the history
* dep: upgrade webpack css mini plugin

* chore: use lightningcss minify option
  • Loading branch information
fz6m authored Nov 23, 2023
1 parent 5a75e3d commit 8825978
Show file tree
Hide file tree
Showing 7 changed files with 783 additions and 159 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"use strict";

/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */

/** @typedef {import("source-map").RawSourceMap} RawSourceMap */

/** @typedef {import("./index.js").InternalResult} InternalResult */

/**
Expand All @@ -13,15 +10,14 @@
*/
const minify = async options => {
const minifyFns = Array.isArray(options.minimizer.implementation) ? options.minimizer.implementation : [options.minimizer.implementation];
/** @type {InternalResult} */

/** @type {InternalResult} */
const result = {
outputs: [],
warnings: [],
errors: []
};
let needSourceMap = false;

for (let i = 0; i <= minifyFns.length - 1; i++) {
const minifyFn = minifyFns[i];
const minifyOptions = Array.isArray(options.minimizer.options) ? options.minimizer.options[i] : options.minimizer.options;
Expand All @@ -32,54 +28,45 @@ const minify = async options => {
const {
code,
map
} = prevResult; // eslint-disable-next-line no-await-in-loop

} = prevResult;
// eslint-disable-next-line no-await-in-loop
const minifyResult = await minifyFn({
[options.name]: code
}, map, minifyOptions);

if (typeof minifyResult.code !== "string") {
throw new Error("minimizer function doesn't return the 'code' property or result is not a string value");
}

if (minifyResult.map) {
needSourceMap = true;
}

if (minifyResult.errors) {
result.errors = result.errors.concat(minifyResult.errors);
}

if (minifyResult.warnings) {
result.warnings = result.warnings.concat(minifyResult.warnings);
}

result.outputs.push({
code: minifyResult.code,
map: minifyResult.map
});
}

if (!needSourceMap) {
result.outputs = [result.outputs[result.outputs.length - 1]];
}

return result;
};

/**
* @param {string} options
* @returns {Promise<InternalResult>}
*/


async function transform(options) {
// 'use strict' => this === undefined (Clean Scope)
// Safer for possible security issues, albeit not critical at all here
// eslint-disable-next-line no-new-func, no-param-reassign
const evaluatedOptions = new Function("exports", "require", "module", "__filename", "__dirname", `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
return minify(evaluatedOptions);
}

module.exports = {
minify,
transform
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"css-minimizer-webpack-plugin","author":"Loann Neveu","license":"MIT","types":"types/index.d.ts"}
{"name":"css-minimizer-webpack-plugin","version":"5.0.1","author":"Loann Neveu","license":"MIT","types":"types/index.d.ts"}
Loading

0 comments on commit 8825978

Please sign in to comment.