Skip to content

Commit edbcb95

Browse files
committed
feature: minify: add support of oxc-minify
1 parent 279500d commit edbcb95

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,11 @@ For cli use these options can be provided in a JSON file named `.minify.json` li
171171
172172
In section related to `js` you can choose `type` of minifier:
173173
174-
- [`putout`](https://github.com/coderaiser/putout); (default);
174+
- [`putout`](https://github.com/putoutjs/minify#readme); (default);
175175
- [`terser`](https://github.com/terser/terser#minify-options);
176176
- [`esbuild`](https://esbuild.github.io/);
177177
- [`swc`](https://swc.rs/docs/configuration/minification);
178+
- [`oxc`](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination.html);
178179
179180
When you want to pass [options](https://github.com/terser/terser#minify-options) to `terser`, use section with the same name, `.minify.json` will look this way:
180181

lib/js.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,12 @@ export default async (source, userOptions) => {
5151
return code;
5252
}
5353

54+
if (options.type === 'oxc') {
55+
const {minify} = await import('oxc-minify');
56+
const {code} = await minify('lib.js', source, options.oxc);
57+
58+
return code;
59+
}
60+
5461
return await minify(source, options.putout);
5562
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"html-minifier-next": "^5.1.5",
4242
"lightningcss": "^1.28.1",
4343
"montag": "^1.2.1",
44+
"oxc-minify": "^0.116.0",
4445
"readjson": "^2.2.2",
4546
"terser": "^5.28.1",
4647
"try-catch": "^4.0.7",

test/minify.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,27 @@ test('minify: js: with alternate options', async (t) => {
117117
t.end();
118118
});
119119

120+
test('minify: js: options: oxc', async (t) => {
121+
const js = 'debugger;const a = 5, b = 6; console.log(a);';
122+
const expected = 'debugger;const a=5,b=6;console.log(5);';
123+
124+
const options = {
125+
js: {
126+
type: 'oxc',
127+
oxc: {
128+
compress: {
129+
dropDebugger: false,
130+
},
131+
},
132+
},
133+
};
134+
135+
const minifyOutput = await minify.js(js, options);
136+
137+
t.equal(minifyOutput, expected, 'js output should be equal');
138+
t.end();
139+
});
140+
120141
test('minify: auto: not found', async (t) => {
121142
const js = 'hello world';
122143
const result = await minify.auto(js, {

0 commit comments

Comments
 (0)