@adamlui/minify.js 1.2.4 → 1.4.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 +134 -42
- package/docs/LICENSE.md +24 -21
- package/docs/SECURITY.md +20 -17
- package/minify.js +212 -150
- package/package.json +48 -48
- package/docs/zh-cn/LICENSE.md +0 -21
- package/docs/zh-cn/README.md +0 -129
- package/docs/zh-cn/SECURITY.md +0 -17
- package/docs/zh-tw/LICENSE.md +0 -21
- package/docs/zh-tw/README.md +0 -128
- package/docs/zh-tw/SECURITY.md +0 -17
package/README.md
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
</picture>
|
|
7
7
|
English |
|
|
8
8
|
<a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/zh-cn#readme">简体中文</a> |
|
|
9
|
-
<a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/zh-tw#readme">繁體中文</a>
|
|
9
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/zh-tw#readme">繁體中文</a> |
|
|
10
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/hi#readme">हिंदी</a> |
|
|
11
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/bn#readme">বাংলা</a> |
|
|
12
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/minify.js/docs/mr#readme">मराठी</a>
|
|
10
13
|
</h6>
|
|
11
14
|
</div>
|
|
12
15
|
|
|
@@ -16,7 +19,7 @@
|
|
|
16
19
|
|
|
17
20
|
<a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/dt/%40adamlui%2Fminify.js?logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
18
21
|
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-red.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
19
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.
|
|
22
|
+
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.0-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
20
23
|
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fminify.js?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
21
24
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:minify.js/minify.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Aminify.js%2Fminify.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
22
25
|
|
|
@@ -34,13 +37,19 @@ As a **global utility**:
|
|
|
34
37
|
npm install -g @adamlui/minify.js
|
|
35
38
|
```
|
|
36
39
|
|
|
37
|
-
As a **dev dependency
|
|
40
|
+
As a **dev dependency** (e.g. for build scripts), from your project root:
|
|
38
41
|
|
|
39
42
|
```
|
|
40
43
|
npm install -D @adamlui/minify.js
|
|
41
44
|
```
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
As a **runtime dependency** (e.g. for on-the-fly minification), from your project root:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
npm install @adamlui/minify.js
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 💻 Command line usage
|
|
44
53
|
|
|
45
54
|
The basic **global command** is:
|
|
46
55
|
|
|
@@ -58,10 +67,10 @@ To specify **input/output** paths:
|
|
|
58
67
|
minify-js [input_path] [output_path]
|
|
59
68
|
```
|
|
60
69
|
|
|
61
|
-
- `[input_path]`: Path to JS file or directory containing JS files to be minified, relative to the current working directory.
|
|
70
|
+
- `[input_path]`: Path to JS file or directory containing JS files to be minified, relative to the current working directory.
|
|
62
71
|
- `[output_path]`: Path to file or directory where minified files will be stored, relative to original file location (if not provided, `min/` is used).
|
|
63
72
|
|
|
64
|
-
**💡 Note:** If folders are passed, files will be processed recursively
|
|
73
|
+
**💡 Note:** If folders are passed, files will be processed recursively unless `-R` or `--no-recursion` is passed.
|
|
65
74
|
|
|
66
75
|
#
|
|
67
76
|
|
|
@@ -76,31 +85,126 @@ To use as a **package script**, in your project's `package.json`:
|
|
|
76
85
|
Replace `<minify-js-cmd>` with `minify-js` + optional args. Then, `npm run build:js` can be used to run the command.
|
|
77
86
|
<br><br>
|
|
78
87
|
|
|
79
|
-
|
|
88
|
+
### Example commands
|
|
89
|
+
|
|
90
|
+
Minify all JavaScript files in the **current directory** (outputs to `min/`):
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
minify-js
|
|
94
|
+
```
|
|
80
95
|
|
|
81
|
-
|
|
96
|
+
Minify all JavaScript files in a **specific directory** (outputs to `path/to/your/directory/min/`):
|
|
82
97
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
98
|
+
```
|
|
99
|
+
minify-js path/to/your/directory
|
|
100
|
+
```
|
|
86
101
|
|
|
87
|
-
|
|
102
|
+
Minify a **specific file** (outputs to `path/to/your/min/file.min.js`):
|
|
88
103
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
```
|
|
105
|
+
minify-js path/to/your/file.js
|
|
106
|
+
```
|
|
92
107
|
|
|
93
|
-
|
|
108
|
+
Specify both **input and output** directories (outputs to `output_folder/`):
|
|
94
109
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
```
|
|
111
|
+
minify-js input_folder output_folder
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Command line options
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
Config options:
|
|
118
|
+
-n, --dry-run Don't actually minify the file(s), just show
|
|
119
|
+
if they will be processed.
|
|
120
|
+
-d, --include-dotfolders Include dotfolders in file search.
|
|
121
|
+
-D, --include-dotfiles Include dotfiles in file search.
|
|
122
|
+
-R, --no-recursion Disable recursive file searching.
|
|
123
|
+
-M, --no-mangle Disable mangling names.
|
|
124
|
+
-q, --quiet Suppress all logging except errors.
|
|
125
|
+
|
|
126
|
+
Info commands:
|
|
127
|
+
-h, --help Display help screen.
|
|
128
|
+
-v, --version Show version number.
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 🔌 API reference
|
|
132
|
+
|
|
133
|
+
You can also import **minify.js** into your app to use its API methods, both as an ECMAScript module or a CommonJS module.
|
|
134
|
+
|
|
135
|
+
#### ESM:
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import * as minifyJS from '@adamlui/minify.js';
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### CJS:
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
const minifyJS = require('@adamlui/minify.js');
|
|
145
|
+
```
|
|
98
146
|
|
|
99
|
-
|
|
147
|
+
### minify(input, options)
|
|
100
148
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
149
|
+
This function minifies JavaScript code based on the string input supplied.
|
|
150
|
+
|
|
151
|
+
If **source code** is passed, it is directly minified, then an object containing `srcPath` + `code` + `error` is returned:
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
const srcCode = 'function add(first, second) { return first + second; }',
|
|
155
|
+
minifyResult = minifyJS.minify(srcCode);
|
|
156
|
+
console.log(minifyResult.error); // runtime error, or `undefined` if no error
|
|
157
|
+
console.log(minifyResult.code); // minified output: function add(n,d){return n+d}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
If a **file path** is passed, the file's code is loaded then minified, returning an object like above.
|
|
161
|
+
|
|
162
|
+
If a **directory path** is passed, JavaScript files are searched for (recursively by default), each one's code is loaded then minified, then an array of objects containing `srcPath` + `code` + `error` is returned:
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
const results = minifyJS.minify('.');
|
|
166
|
+
results.forEach(result =>
|
|
167
|
+
console.log(result.srcPath) // paths to JS files in working directory + all nested directories
|
|
168
|
+
);
|
|
169
|
+
console.log(results[1].code) // minified code of 2nd JS file if found, or `undefined` if not found
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Options are boolean, passed as object properties. For example:
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
minifyJS.minify(input, { dotFiles: true });
|
|
176
|
+
// returns data object where dotfiles are also processed if `input` is a path
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Possible parameters (and their default settings) are:
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
recursive (true) Recursively search for nested files if dir path passed.
|
|
183
|
+
verbose (true) Show logging in console/terminal.
|
|
184
|
+
dotFolders (false) Include dotfolders in file search.
|
|
185
|
+
dotFiles (false) Include dotfiles in file search.
|
|
186
|
+
mangle (true) Shorten variable names (typically to one character).
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### findJS(searchDir, options)
|
|
190
|
+
|
|
191
|
+
This function searches for all unminified JavaScript files within the `searchDir` string passed (useful for discovering what files [`minify()`](#minifyinput-options) will process) and returns an array containing their filepaths.
|
|
192
|
+
|
|
193
|
+
Options are boolean, passed as object properties. For example:
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
minifyJS.findJS(searchDir, { recursive: false });
|
|
197
|
+
// returns array containing filepaths to unminified JS files in exactly `searchDir`
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Possible parameters (and their default settings) are:
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
recursive (true) Recursively search for nested files if dir path passed.
|
|
204
|
+
verbose (false) Show logging in console/terminal.
|
|
205
|
+
dotFolders (false) Include dotfolders in file search.
|
|
206
|
+
dotFiles (false) Include dotfiles in file search.
|
|
207
|
+
```
|
|
104
208
|
|
|
105
209
|
<br>
|
|
106
210
|
|
|
@@ -111,25 +215,13 @@ Please consider [giving a GitHub ⭐](https://github.com/adamlui/js-utils) if th
|
|
|
111
215
|
|
|
112
216
|
## 🏛️ MIT License
|
|
113
217
|
|
|
114
|
-
**Copyright
|
|
115
|
-
|
|
116
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
117
|
-
|
|
118
|
-
in
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
furnished to do so, subject to the following conditions:
|
|
122
|
-
|
|
123
|
-
The above copyright notice and this permission notice shall be included in all
|
|
124
|
-
copies or substantial portions of the Software.
|
|
125
|
-
|
|
126
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
127
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
128
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
129
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
130
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
131
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
132
|
-
SOFTWARE.
|
|
218
|
+
**Copyright © 2023–2024 [Adam Lui](https://github.com/adamlui)**
|
|
219
|
+
|
|
220
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
221
|
+
|
|
222
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
223
|
+
|
|
224
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
133
225
|
|
|
134
226
|
<br>
|
|
135
227
|
|
package/docs/LICENSE.md
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
<div align="right">
|
|
2
|
-
<h6>
|
|
3
|
-
<picture>
|
|
4
|
-
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
-
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
-
</picture>
|
|
7
|
-
English |
|
|
8
|
-
<a href="zh-cn/LICENSE.md">简体中文</a> |
|
|
9
|
-
<a href="zh-tw/LICENSE.md">繁體中文</a>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
English |
|
|
8
|
+
<a href="zh-cn/LICENSE.md">简体中文</a> |
|
|
9
|
+
<a href="zh-tw/LICENSE.md">繁體中文</a> |
|
|
10
|
+
<a href="hi/LICENSE.md">हिंदी</a> |
|
|
11
|
+
<a href="bn/LICENSE.md">বাংলা</a> |
|
|
12
|
+
<a href="mr/LICENSE.md">मराठी</a>
|
|
13
|
+
</h6>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
# 🏛️ MIT License
|
|
17
|
+
|
|
18
|
+
**Copyright © 2023–2024 [Adam Lui](https://github.com/adamlui)**
|
|
19
|
+
|
|
20
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/docs/SECURITY.md
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
<div align="right">
|
|
2
|
-
<h6>
|
|
3
|
-
<picture>
|
|
4
|
-
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
-
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
-
</picture>
|
|
7
|
-
English |
|
|
8
|
-
<a href="zh-cn/SECURITY.md">简体中文</a> |
|
|
9
|
-
<a href="zh-tw/SECURITY.md">繁體中文</a>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
English |
|
|
8
|
+
<a href="zh-cn/SECURITY.md">简体中文</a> |
|
|
9
|
+
<a href="zh-tw/SECURITY.md">繁體中文</a> |
|
|
10
|
+
<a href="hi/SECURITY.md">हिंदी</a> |
|
|
11
|
+
<a href="bn/SECURITY.md">বাংলা</a> |
|
|
12
|
+
<a href="mr/SECURITY.md">मराठी</a>
|
|
13
|
+
</h6>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
# 🛡️ Security Policy
|
|
17
|
+
|
|
18
|
+
If you find a vulnerability, please open a [draft security advisory](https://github.com/adamlui/js-utils/security/advisories/new).
|
|
19
|
+
|
|
20
|
+
Pull requests are also welcome, but for safety reasons, send an email to <adam@kudoai.com> and wait for a response before making it public.
|
package/minify.js
CHANGED
|
@@ -1,150 +1,212 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// Import LIBS
|
|
4
|
-
const fs = require('fs'),
|
|
5
|
-
path = require('path'),
|
|
6
|
-
uglifyJS = require('uglify-js');
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Import LIBS
|
|
4
|
+
const fs = require('fs'),
|
|
5
|
+
path = require('path'),
|
|
6
|
+
uglifyJS = require('uglify-js');
|
|
7
|
+
|
|
8
|
+
// Define MAIN functions
|
|
9
|
+
|
|
10
|
+
function findJS(searchDir, options = {}) {
|
|
11
|
+
const defaultOptions = { recursive: true, verbose: false, dotFolders: false, dotFiles: false };
|
|
12
|
+
options = { ...defaultOptions, ...options };
|
|
13
|
+
const dirFiles = fs.readdirSync(searchDir), jsFiles = [];
|
|
14
|
+
dirFiles.forEach(file => {
|
|
15
|
+
const filePath = path.resolve(searchDir, file);
|
|
16
|
+
if (fs.statSync(filePath).isDirectory() && file != 'node_modules' &&
|
|
17
|
+
(options.dotFolders || !file.startsWith('.')) && options.recursive) {
|
|
18
|
+
if (options.verbose) console.info(`Searching for unminified JS files in: ${filePath}...`);
|
|
19
|
+
jsFiles.push( // recursively find unminified JS in eligible dir
|
|
20
|
+
...findJS(filePath));
|
|
21
|
+
} else if (/\.js(?<!\.min\.js)$/.test(file) &&
|
|
22
|
+
(options.dotFiles || !file.startsWith('.')))
|
|
23
|
+
jsFiles.push(filePath); // store eligible unminified JS file for minification
|
|
24
|
+
});
|
|
25
|
+
return jsFiles;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function minify(input, options = {}) {
|
|
29
|
+
const defaultOptions = {
|
|
30
|
+
recursive: true, verbose: true, dotFolders: false, dotFiles: false, mangle: true };
|
|
31
|
+
options = { ...defaultOptions, ...options };
|
|
32
|
+
if (typeof input !== 'string')
|
|
33
|
+
return console.error('ERROR:'
|
|
34
|
+
+ ' First argument must be a string of source code or file/folder path.');
|
|
35
|
+
const minifyOptions = { mangle: options.mangle ? { toplevel: true } : false };
|
|
36
|
+
if (fs.existsSync(input)) { // minify based on path arg
|
|
37
|
+
if (input.endsWith('.js')) { // file path passed
|
|
38
|
+
if (options.verbose) console.info(`Minifying ${ input }...`);
|
|
39
|
+
const minifyResult = uglifyJS.minify(fs.readFileSync(input, 'utf8'), minifyOptions);
|
|
40
|
+
if (minifyResult.error) console.error(`ERROR: ${ minifyResult.error.message }`);
|
|
41
|
+
return { code: minifyResult.code, srcPath: input, error: minifyResult.error };
|
|
42
|
+
} else { // dir path passed
|
|
43
|
+
return findJS(input, { recursive: options.recursive,
|
|
44
|
+
dotFolders: options.dotFolders, dotFiles: options.dotFiles })
|
|
45
|
+
.map(jsPath => { // minify found JS files
|
|
46
|
+
if (options.verbose) console.info(`Minifying ${ jsPath }...`);
|
|
47
|
+
const srcCode = fs.readFileSync(jsPath, 'utf8'),
|
|
48
|
+
minifyResult = uglifyJS.minify(srcCode, minifyOptions);
|
|
49
|
+
if (minifyResult.error) console.error(`ERROR: ${ minifyResult.error.message }`);
|
|
50
|
+
return { code: minifyResult.code, srcPath: jsPath, error: minifyResult.error };
|
|
51
|
+
}).filter(data => !data.error); // filter out failed minifications
|
|
52
|
+
}
|
|
53
|
+
} else { // minify based on src code arg
|
|
54
|
+
if (options.verbose) console.info('Minifying passed source code...');
|
|
55
|
+
const minifyResult = uglifyJS.minify(input, minifyOptions);
|
|
56
|
+
if (minifyResult.error) console.error(`ERROR: ${ minifyResult.error.message }`);
|
|
57
|
+
return { code: minifyResult.code, srcPath: input, error: minifyResult.error };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// EXPORT functions if script was required
|
|
62
|
+
if (require.main !== module) module.exports = { minify, findJS };
|
|
63
|
+
|
|
64
|
+
else { // run as CLI tool
|
|
65
|
+
|
|
66
|
+
// Init UI colors
|
|
67
|
+
const nc = '\x1b[0m', // no color
|
|
68
|
+
br = '\x1b[1;91m', // bright red
|
|
69
|
+
by = '\x1b[1;33m', // bright yellow
|
|
70
|
+
bg = '\x1b[1;92m'; // bright green
|
|
71
|
+
|
|
72
|
+
// Load FLAG settings
|
|
73
|
+
const config = {
|
|
74
|
+
dryRun: process.argv.some(arg => /^--?(?:n|dry-?run)$/.test(arg)),
|
|
75
|
+
includeDotFolders: process.argv.some(arg =>
|
|
76
|
+
/^--?(?:dd?|(?:include-?)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?)$/.test(arg)),
|
|
77
|
+
includeDotFiles: process.argv.some(arg =>
|
|
78
|
+
/^--?(?:df|D|(?:include-?)?dot-?files?)$/.test(arg)),
|
|
79
|
+
noRecursion: process.argv.some(arg =>
|
|
80
|
+
/^--?(?:R|(?:disable|no)-?recursion)$/.test(arg)),
|
|
81
|
+
noMangle: process.argv.some(arg =>
|
|
82
|
+
/^--?(?:M|(?:disable|no)-?mangle)$/.test(arg)),
|
|
83
|
+
quietMode: process.argv.some(arg => /^--?q(?:uiet)?$/.test(arg))
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Show HELP screen if -h or --help passed
|
|
87
|
+
if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
88
|
+
printHelp(`\n${by}minify-js [inputPath] [outputPath] [options]${nc}`);
|
|
89
|
+
printHelp('\nPath arguments:');
|
|
90
|
+
printHelp(' [inputPath] '
|
|
91
|
+
+ 'Path to JS file or directory containing JS files to be minified,'
|
|
92
|
+
+ ' relative to the current working directory.');
|
|
93
|
+
printHelp(' [outputPath] '
|
|
94
|
+
+ 'Path to file or directory where minified files will be stored,'
|
|
95
|
+
+ ' relative to original file location (if not provided, min/ is used).');
|
|
96
|
+
printHelp('\nConfig options:');
|
|
97
|
+
printHelp(' -n, --dry-run Don\'t actually minify the file(s),'
|
|
98
|
+
+ ' just show if they will be processed.');
|
|
99
|
+
printHelp(' -d, --include-dotfolders Include dotfolders in file search.');
|
|
100
|
+
printHelp(' -D, --include-dotfiles Include dotfiles in file search.');
|
|
101
|
+
printHelp(' -R, --no-recursion Disable recursive file searching.');
|
|
102
|
+
printHelp(' -M, --no-mangle Disable mangling names.');
|
|
103
|
+
printHelp(' -q, --quiet Suppress all logging except errors.');
|
|
104
|
+
printHelp('\nInfo commands:');
|
|
105
|
+
printHelp(' -h, --help Display this help screen.');
|
|
106
|
+
printHelp(' -v, --version Show version number.');
|
|
107
|
+
|
|
108
|
+
// Show VERSION number if -v or --version passed
|
|
109
|
+
} else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
|
|
110
|
+
console.info('v' + require('./package.json').version);
|
|
111
|
+
|
|
112
|
+
} else { // run MAIN routine
|
|
113
|
+
|
|
114
|
+
// Init I/O args
|
|
115
|
+
const [inputArg = '', outputArg = ''] = ( // default to empty strings for error-less handling
|
|
116
|
+
process.argv.slice(2) // exclude executable and script paths
|
|
117
|
+
.filter(arg => !arg.startsWith('-')) // exclude flags
|
|
118
|
+
.map(arg => arg.replace(/^\/*/, '')) // clean leading slashes to avoid parsing system root
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Validate input arg (output arg can be anything)
|
|
122
|
+
const inputPath = path.resolve(process.cwd(), inputArg);
|
|
123
|
+
if (inputArg && !fs.existsSync(inputPath)) {
|
|
124
|
+
console.error(`\n${br}Error: First argument must be an existing file or directory.`
|
|
125
|
+
+ `'\n${ inputPath }' does not exist.${nc}`
|
|
126
|
+
+ `\n\n${bg}Example valid command: \n>> minify-js . output.min.js${nc}`
|
|
127
|
+
+ `\n\n${by}For all command options: \n>> minify-js --help${nc}`);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Find all eligible JavaScript files or arg-passed file
|
|
132
|
+
const unminnedJSfiles = inputArg.endsWith('.js') ? [inputPath]
|
|
133
|
+
: findJS(inputPath, { recursive: !config.noRecursion });
|
|
134
|
+
|
|
135
|
+
if (unminnedJSfiles.length === 0) { // print nothing found
|
|
136
|
+
printIfNotQuiet(`\n${by}No unminified JavaScript files found.${nc}`);
|
|
137
|
+
|
|
138
|
+
} else if (config.dryRun) { // print files to be processed
|
|
139
|
+
console.info(`\n${by}JS files to be minified:${nc}`);
|
|
140
|
+
unminnedJSfiles.forEach(file => console.info(file));
|
|
141
|
+
|
|
142
|
+
} else { // actually minify JavaScript files
|
|
143
|
+
printIfNotQuiet(''); // line break before first log
|
|
144
|
+
|
|
145
|
+
// Build array of minification data
|
|
146
|
+
const failedPaths = [];
|
|
147
|
+
const minifyData = unminnedJSfiles.map(jsPath => {
|
|
148
|
+
const minifyResult = minify(jsPath, { verbose: !config.quietMode, mangle: !config.noMangle });
|
|
149
|
+
if (minifyResult.error) failedPaths.push(jsPath);
|
|
150
|
+
return minifyResult;
|
|
151
|
+
}).filter(minifyResult => !minifyResult.error); // filter out failed minifications
|
|
152
|
+
|
|
153
|
+
// Write array data to files
|
|
154
|
+
minifyData.forEach(({ code, srcPath }) => {
|
|
155
|
+
const outputDir = path.join(
|
|
156
|
+
path.dirname(srcPath), // path of file to be minified
|
|
157
|
+
/so?u?rce?$/.test(path.dirname(srcPath)) ? '../min' // + ../min/ if in *(src|source)/
|
|
158
|
+
: outputArg.endsWith('.js') ? path.dirname(outputArg) // or path from file output arg
|
|
159
|
+
: outputArg || 'min' // or path from folder output arg or min/ if no output arg passed
|
|
160
|
+
);
|
|
161
|
+
const outputFilename = (
|
|
162
|
+
outputArg.endsWith('.js') && inputArg.endsWith('.js')
|
|
163
|
+
? path.basename(outputArg).replace(/(\.min)?\.js$/, '')
|
|
164
|
+
: path.basename(srcPath, '.js')
|
|
165
|
+
) + '.min.js';
|
|
166
|
+
const outputPath = path.join(outputDir, outputFilename);
|
|
167
|
+
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
|
|
168
|
+
fs.writeFileSync(outputPath, code, 'utf8');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Print final summary
|
|
172
|
+
if (minifyData.length > 0) {
|
|
173
|
+
printIfNotQuiet(`\n${bg}Minification complete!${nc}`);
|
|
174
|
+
printIfNotQuiet(
|
|
175
|
+
`${ minifyData.length } file${ minifyData.length > 1 ? 's' : '' } minified.`);
|
|
176
|
+
} else printIfNotQuiet(`${by}No unminified JavaScript files processed successfully.${nc}`);
|
|
177
|
+
if (failedPaths.length > 0) {
|
|
178
|
+
printIfNotQuiet(`\n${br}`
|
|
179
|
+
+ `${ failedPaths.length } file${ failedPaths.length > 1 ? 's' : '' }`
|
|
180
|
+
+ ` failed to minify:${nc}`);
|
|
181
|
+
failedPaths.forEach(path => printIfNotQuiet(path));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Define LOGGING functions
|
|
187
|
+
|
|
188
|
+
function printHelp(msg) { // wrap msg + indent 2nd+ lines (for --help screen)
|
|
189
|
+
const terminalWidth = process.stdout.columns || 80,
|
|
190
|
+
indentation = 29, lines = [], words = msg.match(/\S+|\s+/g);
|
|
191
|
+
|
|
192
|
+
// Split msg into lines of appropriate lengths
|
|
193
|
+
let currentLine = '';
|
|
194
|
+
words.forEach(word => {
|
|
195
|
+
const lineLength = terminalWidth - ( lines.length === 0 ? 0 : indentation );
|
|
196
|
+
if (currentLine.length + word.length > lineLength) { // cap/store it
|
|
197
|
+
lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
|
|
198
|
+
currentLine = '';
|
|
199
|
+
}
|
|
200
|
+
currentLine += word;
|
|
201
|
+
});
|
|
202
|
+
lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
|
|
203
|
+
|
|
204
|
+
// Print formatted msg
|
|
205
|
+
lines.forEach((line, index) => console.info(
|
|
206
|
+
index === 0 ? line // print 1st line unindented
|
|
207
|
+
: ' '.repeat(indentation) + line // print subsequent lines indented
|
|
208
|
+
));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function printIfNotQuiet(msg) { if (!config.quietMode) console.info(msg); }
|
|
212
|
+
}
|
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@adamlui/minify.js",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Recursively minify all JavaScript files",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Adam Lui",
|
|
7
|
-
"email": "adam@kudoai.com",
|
|
8
|
-
"url": "https://github.com/adamlui"
|
|
9
|
-
},
|
|
10
|
-
"homepage": "https://github.com/adamlui/js-utils",
|
|
11
|
-
"license": "MIT",
|
|
12
|
-
"main": "minify.js",
|
|
13
|
-
"bin": {
|
|
14
|
-
"minifyjs": "minify.js",
|
|
15
|
-
"minify-js": "minify.js"
|
|
16
|
-
},
|
|
17
|
-
"scripts": {
|
|
18
|
-
"test": "bash utils/test/minify.test.sh",
|
|
19
|
-
"bump:patch": "bash utils/bump.sh patch",
|
|
20
|
-
"bump:minor": "bash utils/bump.sh minor",
|
|
21
|
-
"bump:major": "bash utils/bump.sh major",
|
|
22
|
-
"publish:patch": "bash utils/bump.sh patch --publish",
|
|
23
|
-
"publish:minor": "bash utils/bump.sh minor --publish",
|
|
24
|
-
"publish:major": "bash utils/bump.sh major --publish"
|
|
25
|
-
},
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/adamlui/js-utils.git"
|
|
29
|
-
},
|
|
30
|
-
"keywords": [
|
|
31
|
-
"javascript",
|
|
32
|
-
"js",
|
|
33
|
-
"js-utils",
|
|
34
|
-
"utils",
|
|
35
|
-
"utilities",
|
|
36
|
-
"minifier"
|
|
37
|
-
],
|
|
38
|
-
"bugs": {
|
|
39
|
-
"url": "https://github.com/adamlui/js-utils/issues"
|
|
40
|
-
},
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"uglify-js": "^3.17.4"
|
|
43
|
-
},
|
|
44
|
-
"funding": {
|
|
45
|
-
"type": "github",
|
|
46
|
-
"url": "https://github.com/sponsors/adamlui"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@adamlui/minify.js",
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "Recursively minify all JavaScript files",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Adam Lui",
|
|
7
|
+
"email": "adam@kudoai.com",
|
|
8
|
+
"url": "https://github.com/adamlui"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/adamlui/js-utils",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"main": "minify.js",
|
|
13
|
+
"bin": {
|
|
14
|
+
"minifyjs": "minify.js",
|
|
15
|
+
"minify-js": "minify.js"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "bash utils/test/minify.test.sh",
|
|
19
|
+
"bump:patch": "bash utils/bump.sh patch",
|
|
20
|
+
"bump:minor": "bash utils/bump.sh minor",
|
|
21
|
+
"bump:major": "bash utils/bump.sh major",
|
|
22
|
+
"publish:patch": "bash utils/bump.sh patch --publish",
|
|
23
|
+
"publish:minor": "bash utils/bump.sh minor --publish",
|
|
24
|
+
"publish:major": "bash utils/bump.sh major --publish"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/adamlui/js-utils.git"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"javascript",
|
|
32
|
+
"js",
|
|
33
|
+
"js-utils",
|
|
34
|
+
"utils",
|
|
35
|
+
"utilities",
|
|
36
|
+
"minifier"
|
|
37
|
+
],
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/adamlui/js-utils/issues"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"uglify-js": "^3.17.4"
|
|
43
|
+
},
|
|
44
|
+
"funding": {
|
|
45
|
+
"type": "github",
|
|
46
|
+
"url": "https://github.com/sponsors/adamlui"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/docs/zh-cn/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
<div align="right">
|
|
2
|
-
<h6>
|
|
3
|
-
<picture>
|
|
4
|
-
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
-
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
-
</picture>
|
|
7
|
-
简体中文 |
|
|
8
|
-
<a href="../LICENSE.md">English</a> |
|
|
9
|
-
<a href="../zh-tw/LICENSE.md">繁體中文</a>
|
|
10
|
-
</h6>
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
# 🏛️ MIT 许可证
|
|
14
|
-
|
|
15
|
-
**版权所有 (c) 2023–2024 [刘展鹏 (Adam Lui)](https://github.com/adamlui)**
|
|
16
|
-
|
|
17
|
-
特此免费向任何获得副本的人授予许可本软件和相关文档文件(『软件』),处理在软件中不受限制,包括但不限于权利使用、复制、修改、合并、发布、分发、再许可和/或出售该软件的副本,并允许该软件是提供这样做,但须满足以下条件:
|
|
18
|
-
|
|
19
|
-
上述版权声明和本许可声明应包含在所有软件的副本或重要部分。
|
|
20
|
-
|
|
21
|
-
本软件『按原样』提供,不提供任何形式的明示或保证暗示的,包括但不限于适销性保证,适用于特定目的和非侵权。 在任何情况下都不得作者或版权持有人对任何索赔、损害或其他责任,无论是在合同、侵权或其他方面的行为中,由以下原因引起,出于或与软件或使用或其他交易有关软件。
|
package/docs/zh-cn/README.md
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
<div align="right">
|
|
2
|
-
<h6>
|
|
3
|
-
<picture>
|
|
4
|
-
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
-
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
-
</picture>
|
|
7
|
-
简体中文 |
|
|
8
|
-
<a href="../..#readme">English</a> |
|
|
9
|
-
<a href="../zh-tw#readme">繁體中文</a>
|
|
10
|
-
</h6>
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
# </> minify.js
|
|
14
|
-
|
|
15
|
-
### 递归地缩小所有 JavaScript 文件。
|
|
16
|
-
|
|
17
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/dt/%40adamlui%2Fminify.js?label=%E4%B8%8B%E8%BD%BD&logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
18
|
-
<a href="#%EF%B8%8F-mit-%E8%AE%B8%E5%8F%AF%E8%AF%81"><img height=31 src="https://img.shields.io/badge/许可证-MIT-red.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
19
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=versions"><img height=31 src="https://img.shields.io/badge/最新版本-1.2.4-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
20
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fminify.js?label=%E6%8B%86%E5%B0%81%E5%B0%BA%E5%AF%B8&style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
21
|
-
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:minify.js/minify.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Aminify.js%2Fminify.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=%E6%BC%8F%E6%B4%9E&color=gold"></a>
|
|
22
|
-
|
|
23
|
-
<img src="https://github.com/adamlui/js-utils/blob/main/minify.js/media/images/minify.js-docs-demo.png">
|
|
24
|
-
|
|
25
|
-
<br>
|
|
26
|
-
|
|
27
|
-
<img height=8px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
28
|
-
|
|
29
|
-
## ⚡ 如何安装
|
|
30
|
-
|
|
31
|
-
作为**全局实用程序**:
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
npm install -g @adamlui/minify.js
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
作为**开发依赖**,从项目根目录:
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
npm install -D @adamlui/minify.js
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## 💻 用法
|
|
44
|
-
|
|
45
|
-
基本的**全局命令**是:
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
minify-js
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
**💡 注意:** 通过 `-n` 或 `--dry-run` 来仅查看将处理哪些文件。
|
|
52
|
-
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
指定**输入/输出**路径:
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
minify-js [input_path] [output_path]
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
- `[input_path]`: 相对于当前工作目录的 JS 文件或包含要缩小的 JS 文件的目录的路径。
|
|
62
|
-
- `[output_path]`: 将存储缩小文件的文件或目录的路径,相对于原始文件位置(如果未提供,则使用 `min/`)。
|
|
63
|
-
|
|
64
|
-
**💡 注意:** 如果传递文件夹,文件将被递归处理。 要包含点文件夹,请传递 `-d` 或 `--include-dotfolders`。 要包含点文件,请传递 `-D` 或 `--include-dotfiles`。
|
|
65
|
-
|
|
66
|
-
#
|
|
67
|
-
|
|
68
|
-
要用作 **包脚本**,请在项目的 `package.json` 中:
|
|
69
|
-
|
|
70
|
-
```json
|
|
71
|
-
"scripts": {
|
|
72
|
-
"build:js": "<minify-js-cmd>"
|
|
73
|
-
},
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
将 `<minify-js-cmd>` 替换为 `minify-js` + 可选参数。 然后,可以使用 `npm run build:js` 来运行该命令。
|
|
77
|
-
<br><br>
|
|
78
|
-
|
|
79
|
-
## 📃 命令示例:
|
|
80
|
-
|
|
81
|
-
- 缩小**当前目录**中的所有 JavaScript 文件(输出到 `min/`):
|
|
82
|
-
|
|
83
|
-
```
|
|
84
|
-
minify-js
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
- 缩小**特定目录**中的所有 JavaScript 文件(输出到 `path/to/your/directory/min/`):
|
|
88
|
-
|
|
89
|
-
```
|
|
90
|
-
minify-js path/to/your/directory
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
- 缩小**特定文件**(输出到 `path/to/your/min/file.min.js`):
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
minify-js path/to/your/file.js
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
- 指定**输入和输出**目录(输出到 `output_folder/`):
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
minify-js input_folder output_folder
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
<br>
|
|
106
|
-
|
|
107
|
-
## 💖 支持
|
|
108
|
-
|
|
109
|
-
如果这对您有帮助,请考虑[给予 GitHub ⭐](https://github.com/adamlui/js-utils)!
|
|
110
|
-
<br><br>
|
|
111
|
-
|
|
112
|
-
## 🏛️ MIT 许可证
|
|
113
|
-
|
|
114
|
-
**版权所有 (c) 2023–2024 [刘展鹏 (Adam Lui)](https://github.com/adamlui)**
|
|
115
|
-
|
|
116
|
-
特此免费向任何获得副本的人授予许可本软件和相关文档文件(『软件』),处理在软件中不受限制,包括但不限于权利使用、复制、修改、合并、发布、分发、再许可和/或出售该软件的副本,并允许该软件是提供这样做,但须满足以下条件:
|
|
117
|
-
|
|
118
|
-
上述版权声明和本许可声明应包含在所有软件的副本或重要部分。
|
|
119
|
-
|
|
120
|
-
本软件『按原样』提供,不提供任何形式的明示或保证暗示的,包括但不限于适销性保证,适用于特定目的和非侵权。 在任何情况下都不得作者或版权持有人对任何索赔、损害或其他责任,无论是在合同、侵权或其他方面的行为中,由以下原因引起,出于或与软件或使用或其他交易有关
|
|
121
|
-
软件。
|
|
122
|
-
|
|
123
|
-
<br>
|
|
124
|
-
|
|
125
|
-
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
126
|
-
|
|
127
|
-
<a href="https://github.com/adamlui/js-utils">**家**</a> /
|
|
128
|
-
<a href="https://github.com/adamlui/js-utils/discussions">讨论</a> /
|
|
129
|
-
<a href="#-minifyjs">回到顶部 ↑</a>
|
package/docs/zh-cn/SECURITY.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<div align="right">
|
|
2
|
-
<h6>
|
|
3
|
-
<picture>
|
|
4
|
-
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
-
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
-
</picture>
|
|
7
|
-
简体中文 |
|
|
8
|
-
<a href="../SECURITY.md">English</a> |
|
|
9
|
-
<a href="../zh-tw/SECURITY.md">繁體中文</a>
|
|
10
|
-
</h6>
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
# 🛡️ 安全政策
|
|
14
|
-
|
|
15
|
-
如果您发现漏洞,请打开[安全公告草案](https://github.com/adamlui/js-utils/security/advisories/new)。
|
|
16
|
-
|
|
17
|
-
也欢迎拉取请求,但出于安全原因,请发送电子邮件至 <adam@kudoai.com> 并等待回复后再公开。
|
package/docs/zh-tw/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
<div align="right">
|
|
2
|
-
<h6>
|
|
3
|
-
<picture>
|
|
4
|
-
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
-
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
-
</picture>
|
|
7
|
-
繁體中文 |
|
|
8
|
-
<a href="../LICENSE.md">English</a> |
|
|
9
|
-
<a href="../zh-cn/LICENSE.md">简体中文</a>
|
|
10
|
-
</h6>
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
# 🏛️ MIT 许可证
|
|
14
|
-
|
|
15
|
-
**版權所有 (c) 2023–2024 [刘展鹏 (Adam Lui)](https://github.com/adamlui)**
|
|
16
|
-
|
|
17
|
-
特此免費授予任何取得副本的人許可本軟體和相關文件文件(『軟體』),處理在軟體中不受限制,包括但不限於權利使用、複製、修改、合併、發布、分發、再授權和/或出售該軟體的副本,並允許該軟體是提供這樣做,但須滿足以下條件:
|
|
18
|
-
|
|
19
|
-
上述版權聲明和本許可聲明應包含在所有軟體的副本或重要部分。
|
|
20
|
-
|
|
21
|
-
本軟體『依現況』提供,不提供任何形式的明示或保證暗示的,包括但不限於適銷性保證,適用於特定目的和非侵權。 在任何情況下都不得作者或版權持有人對任何索賠、損害或其他責任,無論是在合約、侵權或其他方面的行為中,由以下原因引起,出於或與軟體或使用或其他交易有關軟體。
|
package/docs/zh-tw/README.md
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
<div align="right">
|
|
2
|
-
<h6>
|
|
3
|
-
<picture>
|
|
4
|
-
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
-
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
-
</picture>
|
|
7
|
-
繁體中文 |
|
|
8
|
-
<a href="../..#readme">English</a> |
|
|
9
|
-
<a href="../zh-cn#readme">简体中文</a>
|
|
10
|
-
</h6>
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
# </> minify.js
|
|
14
|
-
|
|
15
|
-
### 遞歸地縮小所有 JavaScript 檔案。
|
|
16
|
-
|
|
17
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/dt/%40adamlui%2Fminify.js?label=%E4%B8%8B%E8%BC%89&logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
18
|
-
<a href="#%EF%B8%8F-mit-%E8%A8%B1%E5%8F%AF%E8%AD%89"><img height=31 src="https://img.shields.io/badge/許可證-MIT-red.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
19
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=versions"><img height=31 src="https://img.shields.io/badge/最新版本-1.2.4-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
20
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fminify.js?label=%E6%8B%86%E5%B0%81%E5%B0%BA%E5%AF%B8&style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
21
|
-
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:minify.js/minify.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Aminify.js%2Fminify.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=%E6%BC%8F%E6%B4%9E&color=gold"></a>
|
|
22
|
-
|
|
23
|
-
<img src="https://github.com/adamlui/js-utils/blob/main/minify.js/media/images/minify.js-docs-demo.png">
|
|
24
|
-
|
|
25
|
-
<br>
|
|
26
|
-
|
|
27
|
-
<img height=8px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
28
|
-
|
|
29
|
-
## ⚡ 如何安裝
|
|
30
|
-
|
|
31
|
-
作為**全域實用程式**:
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
npm install -g @adamlui/minify.js
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
作為**開發依賴**,從專案根目錄:
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
npm install -D @adamlui/minify.js
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## 💻 用法
|
|
44
|
-
|
|
45
|
-
基本的**全域命令**是:
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
minify-js
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
**💡 注意:** 透過 `-n` 或 `--dry-run` 來只查看將處理哪些檔案。
|
|
52
|
-
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
指定**輸入/輸出**路徑:
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
minify-js [input_path] [output_path]
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
- `[input_path]`: 相對於目前工作目錄的 JS 檔案或包含要縮小的 JS 檔案的目錄的路徑。
|
|
62
|
-
- `[output_path]`: 將儲存縮小檔案的檔案或目錄的路徑,相對於原始檔案位置(如果未提供,則使用 `min/`)。
|
|
63
|
-
|
|
64
|
-
**💡 注意:** 如果傳遞資料夾,檔案將會被遞歸處理。 若要包含點資料夾,請傳遞 `-d` 或 `--include-dotfolders`。 若要包含點文件,請傳遞 `-D` 或 `--include-dotfiles`。
|
|
65
|
-
|
|
66
|
-
#
|
|
67
|
-
|
|
68
|
-
若要用作 **套件腳本**,請在專案的 `package.json` 中:
|
|
69
|
-
|
|
70
|
-
```json
|
|
71
|
-
"scripts": {
|
|
72
|
-
"build:js": "<minify-js-cmd>"
|
|
73
|
-
},
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
將 `<minify-js-cmd>` 替換為 `minify-js` + 可選參數。 然後,可以使用 `npm run build:js` 來執行該指令。
|
|
77
|
-
<br><br>
|
|
78
|
-
|
|
79
|
-
## 📃 命令範例:
|
|
80
|
-
|
|
81
|
-
- 縮小**目前目錄**中的所有 JavaScript 檔案(輸出到 `min/`):
|
|
82
|
-
|
|
83
|
-
```
|
|
84
|
-
minify-js
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
- 縮小**特定目錄**中的所有 JavaScript 檔案(輸出到 `path/to/your/directory/min/`):
|
|
88
|
-
|
|
89
|
-
```
|
|
90
|
-
minify-js path/to/your/directory
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
- 縮小**特定檔案**(輸出到 `path/to/your/min/file.min.js`):
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
minify-js path/to/your/file.js
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
- 指定**輸入和輸出**目錄(輸出到 `output_folder/`):
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
minify-js input_folder output_folder
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
<br>
|
|
106
|
-
|
|
107
|
-
## 💖 支援
|
|
108
|
-
|
|
109
|
-
如果這對您有幫助,請考慮[給予 GitHub ⭐](https://github.com/adamlui/js-utils)!
|
|
110
|
-
<br><br>
|
|
111
|
-
|
|
112
|
-
## 🏛️ MIT 许可证
|
|
113
|
-
|
|
114
|
-
**版權所有 (c) 2023–2024 [刘展鹏 (Adam Lui)](https://github.com/adamlui)**
|
|
115
|
-
|
|
116
|
-
特此向任何獲得副本的人免費授予許可本軟件和相關文檔文件(『軟件』)的,以處理不受限制地使用軟件,包括但不限於權利使用、複製、修改、合併、發布、分發、再許可和/或出售該軟件的副本,並允許該軟件的使用者可以這樣做,但須滿足以下條件:
|
|
117
|
-
|
|
118
|
-
上述版權聲明和本許可聲明應包含在所有內容中軟件的副本或主要部分。
|
|
119
|
-
|
|
120
|
-
該軟件按『原樣』提供,不提供任何形式的明示或保證默示的保證,包括但不限於適銷性保證,適用於特定目的且不侵權。 在任何情況下都不得作者或版權所有者對任何索賠、損害或其他責任負責責任,無論是合同訴訟、侵權訴訟還是其他訴訟,均由以下原因引起:與本軟件無關或與之相關,或者與本軟件相關的使用或其他交易軟件。
|
|
121
|
-
|
|
122
|
-
<br>
|
|
123
|
-
|
|
124
|
-
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
125
|
-
|
|
126
|
-
<a href="https://github.com/adamlui/js-utils">**家**</a> /
|
|
127
|
-
<a href="https://github.com/adamlui/js-utils/discussions">讨论</a> /
|
|
128
|
-
<a href="#-minifyjs">回到顶部 ↑</a>
|
package/docs/zh-tw/SECURITY.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<div align="right">
|
|
2
|
-
<h6>
|
|
3
|
-
<picture>
|
|
4
|
-
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
-
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
-
</picture>
|
|
7
|
-
繁體中文 |
|
|
8
|
-
<a href="../SECURITY.md">English</a> |
|
|
9
|
-
<a href="../zh-cn/SECURITY.md">简体中文</a>
|
|
10
|
-
</h6>
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
# 🛡️ 安全策略
|
|
14
|
-
|
|
15
|
-
如果您發現漏洞,請打開[安全公告草案](https://github.com/adamlui/js-utils/security/advisories/new)。
|
|
16
|
-
|
|
17
|
-
也歡迎拉取請求,但出於安全原因,請發送電子郵件至 <adam@kudoai.com> 並等待回復後再公開。
|