Skip to content

Commit a7ca390

Browse files
authored
fix: wrong match object logic in SwcJsMinimizerRspackPlugin (#11496)
1 parent 3c6254c commit a7ca390

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

crates/rspack_plugin_swc_js_minimizer/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,10 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
368368
}
369369

370370
pub fn match_object(obj: &PluginOptions, str: &str) -> bool {
371-
if let Some(condition) = &obj.test
372-
&& !condition.try_match(str)
373-
{
374-
return false;
371+
if let Some(condition) = &obj.test {
372+
if !condition.try_match(str) {
373+
return false;
374+
}
375375
} else if !JAVASCRIPT_ASSET_REGEXP.is_match(str) {
376376
return false;
377377
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const fs = require("node:fs")
2+
3+
console.log("line1")
4+
console.log("line2")
5+
console.log("line3")
6+
7+
it('should minimize *.bundle', () => {
8+
const content = fs.readFileSync(__filename, "utf-8");
9+
10+
expect(content.split(/\r?\n/).length).toBe(1);
11+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { rspack } = require("@rspack/core");
2+
3+
/** @type {import("@rspack/core").Configuration} */
4+
module.exports = {
5+
output: {
6+
filename: "[name].bundle"
7+
},
8+
optimization: {
9+
minimize: true,
10+
minimizer: [
11+
new rspack.SwcJsMinimizerRspackPlugin({
12+
test: /\.bundle$/
13+
})
14+
]
15+
}
16+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import("../../../..").TConfigCaseConfig} */
2+
module.exports = {
3+
findBundle: (i, options) => {
4+
return ["main.bundle"];
5+
}
6+
};

0 commit comments

Comments
 (0)