oxc-minify 0.56.5 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/index.d.ts +17 -12
- package/package.json +23 -15
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
1
|
# Oxc Minify
|
|
2
2
|
|
|
3
3
|
This is alpha software and may yield incorrect results, feel free to [submit a bug report](https://github.com/oxc-project/oxc/issues/new?assignees=&labels=C-bug&projects=&template=bug_report.md).
|
|
4
|
+
|
|
5
|
+
### Performance and Compression Size
|
|
6
|
+
|
|
7
|
+
See [minification-benchmarks](https://github.com/privatenumber/minification-benchmarks) for details.
|
|
8
|
+
|
|
9
|
+
The current version already outperforms `esbuild`,
|
|
10
|
+
but it still lacks a few key minification techniques
|
|
11
|
+
such as constant inlining and dead code removal,
|
|
12
|
+
which we plan to implement next.
|
|
13
|
+
|
|
14
|
+
## Caveats
|
|
15
|
+
|
|
16
|
+
To maximize performance, `oxc-minify` assumes the input code is semantically correct.
|
|
17
|
+
It uses `oxc-parser`'s fast mode to parse the input code,
|
|
18
|
+
which does not check for semantic errors related to symbols and scopes.
|
|
19
|
+
|
|
20
|
+
## API
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
import { minify } from 'oxc-minify';
|
|
24
|
+
|
|
25
|
+
const filename = 'test.js';
|
|
26
|
+
const code = "const x = 'a' + 'b'; console.log(x);";
|
|
27
|
+
const options = {
|
|
28
|
+
compress: {
|
|
29
|
+
target: 'esnext',
|
|
30
|
+
},
|
|
31
|
+
mangle: {
|
|
32
|
+
toplevel: false,
|
|
33
|
+
},
|
|
34
|
+
codegen: {
|
|
35
|
+
removeWhitespace: true,
|
|
36
|
+
},
|
|
37
|
+
sourcemap: true,
|
|
38
|
+
};
|
|
39
|
+
const result = minify(filename, code, options);
|
|
40
|
+
|
|
41
|
+
console.log(result.code);
|
|
42
|
+
console.log(result.map);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Assumptions
|
|
46
|
+
|
|
47
|
+
`oxc-minify` makes some assumptions about the source code.
|
|
48
|
+
|
|
49
|
+
See https://github.com/oxc-project/oxc/blob/main/crates/oxc_minifier/README.md#assumptions for details.
|
package/index.d.ts
CHANGED
|
@@ -6,16 +6,23 @@ export interface CodegenOptions {
|
|
|
6
6
|
*
|
|
7
7
|
* @default true
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
removeWhitespace?: boolean
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface CompressOptions {
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Set desired EcmaScript standard version for output.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* Set `esnext` to enable all target highering.
|
|
17
|
+
*
|
|
18
|
+
* e.g.
|
|
19
|
+
*
|
|
20
|
+
* * catch optional binding when >= es2019
|
|
21
|
+
* * `??` operator >= es2020
|
|
22
|
+
*
|
|
23
|
+
* @default 'esnext'
|
|
17
24
|
*/
|
|
18
|
-
target?:
|
|
25
|
+
target?: 'esnext' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'es2023' | 'es2024'
|
|
19
26
|
/**
|
|
20
27
|
* Pass true to discard calls to `console.*`.
|
|
21
28
|
*
|
|
@@ -31,19 +38,17 @@ export interface CompressOptions {
|
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
export interface MangleOptions {
|
|
34
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Pass `true` to mangle names declared in the top level scope.
|
|
43
|
+
*
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
35
46
|
toplevel?: boolean
|
|
36
47
|
/** Debug mangled names. */
|
|
37
48
|
debug?: boolean
|
|
38
49
|
}
|
|
39
50
|
|
|
40
|
-
/**
|
|
41
|
-
* Minify synchronously.
|
|
42
|
-
*
|
|
43
|
-
* # Errors
|
|
44
|
-
*
|
|
45
|
-
* * Fails to parse the options.
|
|
46
|
-
*/
|
|
51
|
+
/** Minify synchronously. */
|
|
47
52
|
export declare function minify(filename: string, sourceText: string, options?: MinifyOptions | undefined | null): MinifyResult
|
|
48
53
|
|
|
49
54
|
export interface MinifyOptions {
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxc-minify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"browser": "browser.js",
|
|
6
|
-
"
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=14.0.0"
|
|
8
|
+
},
|
|
9
|
+
"description": "Oxc Minifier Node API",
|
|
7
10
|
"keywords": [
|
|
8
11
|
"oxc",
|
|
9
12
|
"minify"
|
|
@@ -15,7 +18,7 @@
|
|
|
15
18
|
"repository": {
|
|
16
19
|
"type": "git",
|
|
17
20
|
"url": "https://github.com/oxc-project/oxc.git",
|
|
18
|
-
"directory": "
|
|
21
|
+
"directory": "napi/minify"
|
|
19
22
|
},
|
|
20
23
|
"funding": {
|
|
21
24
|
"url": "https://github.com/sponsors/Boshen"
|
|
@@ -29,8 +32,8 @@
|
|
|
29
32
|
"registry": "https://registry.npmjs.org/",
|
|
30
33
|
"access": "public"
|
|
31
34
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"vitest": "3.0.7"
|
|
34
37
|
},
|
|
35
38
|
"napi": {
|
|
36
39
|
"binaryName": "minify",
|
|
@@ -54,15 +57,20 @@
|
|
|
54
57
|
}
|
|
55
58
|
},
|
|
56
59
|
"optionalDependencies": {
|
|
57
|
-
"@oxc-minify/binding-win32-x64-msvc": "0.
|
|
58
|
-
"@oxc-minify/binding-win32-arm64-msvc": "0.
|
|
59
|
-
"@oxc-minify/binding-linux-x64-gnu": "0.
|
|
60
|
-
"@oxc-minify/binding-linux-x64-musl": "0.
|
|
61
|
-
"@oxc-minify/binding-linux-arm64-gnu": "0.
|
|
62
|
-
"@oxc-minify/binding-linux-arm64-musl": "0.
|
|
63
|
-
"@oxc-minify/binding-linux-arm-gnueabihf": "0.
|
|
64
|
-
"@oxc-minify/binding-darwin-x64": "0.
|
|
65
|
-
"@oxc-minify/binding-darwin-arm64": "0.
|
|
66
|
-
"@oxc-minify/binding-wasm32-wasi": "0.
|
|
60
|
+
"@oxc-minify/binding-win32-x64-msvc": "0.58.0",
|
|
61
|
+
"@oxc-minify/binding-win32-arm64-msvc": "0.58.0",
|
|
62
|
+
"@oxc-minify/binding-linux-x64-gnu": "0.58.0",
|
|
63
|
+
"@oxc-minify/binding-linux-x64-musl": "0.58.0",
|
|
64
|
+
"@oxc-minify/binding-linux-arm64-gnu": "0.58.0",
|
|
65
|
+
"@oxc-minify/binding-linux-arm64-musl": "0.58.0",
|
|
66
|
+
"@oxc-minify/binding-linux-arm-gnueabihf": "0.58.0",
|
|
67
|
+
"@oxc-minify/binding-darwin-x64": "0.58.0",
|
|
68
|
+
"@oxc-minify/binding-darwin-arm64": "0.58.0",
|
|
69
|
+
"@oxc-minify/binding-wasm32-wasi": "0.58.0"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build-dev": "napi build --no-dts-cache --platform",
|
|
73
|
+
"build": "pnpm run build-dev --release",
|
|
74
|
+
"test": "vitest --typecheck run ./test && tsc"
|
|
67
75
|
}
|
|
68
76
|
}
|