@adamlui/minify.js 1.2.4 → 1.3.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 CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  <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
18
  <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.2.4-fc7811.svg?logo=icinga&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.3.0-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
20
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?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
21
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=Vulnerabilities&color=gold"></a>
22
22
 
@@ -40,7 +40,7 @@ As a **dev dependency**, from your project root:
40
40
  npm install -D @adamlui/minify.js
41
41
  ```
42
42
 
43
- ## 💻 Usage
43
+ ## 💻 Command line usage
44
44
 
45
45
  The basic **global command** is:
46
46
 
@@ -61,7 +61,7 @@ minify-js [input_path] [output_path]
61
61
  - `[input_path]`: Path to JS file or directory containing JS files to be minified, relative to the current working directory.
62
62
  - `[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
63
 
64
- **💡 Note:** If folders are passed, files will be processed recursively. To include dotfolders, pass `-d` or `--include-dotfolders`. To include dotfiles, pass `-D` or `--include-dotfiles`.
64
+ **💡 Note:** If folders are passed, files will be processed recursively.
65
65
 
66
66
  #
67
67
 
@@ -76,31 +76,94 @@ To use as a **package script**, in your project's `package.json`:
76
76
  Replace `<minify-js-cmd>` with `minify-js` + optional args. Then, `npm run build:js` can be used to run the command.
77
77
  <br><br>
78
78
 
79
- ## 📃 Example commands:
79
+ ### Command line options
80
80
 
81
- - Minify all JavaScript files in the **current directory** (outputs to `min/`):
81
+ ```
82
+ Config options:
83
+ -n, --dry-run Don't actually minify the file(s), just show
84
+ if they will be processed.
85
+ -d, --include-dotfolders Include dotfolders in file search.
86
+ -D, --include-dotfiles Include dotfiles in file search.
87
+ -q, --quiet Suppress all logging except errors.
88
+
89
+ Info commands:
90
+ -h, --help Display help screen.
91
+ -v, --version Show version number.
92
+ ```
82
93
 
83
- ```
84
- minify-js
85
- ```
94
+ ### Example commands
86
95
 
87
- - Minify all JavaScript files in a **specific directory** (outputs to `path/to/your/directory/min/`):
96
+ Minify all JavaScript files in the **current directory** (outputs to `min/`):
88
97
 
89
- ```
90
- minify-js path/to/your/directory
91
- ```
98
+ ```
99
+ minify-js
100
+ ```
92
101
 
93
- - Minify a **specific file** (outputs to `path/to/your/min/file.min.js`):
102
+ Minify all JavaScript files in a **specific directory** (outputs to `path/to/your/directory/min/`):
94
103
 
95
- ```
96
- minify-js path/to/your/file.js
97
- ```
104
+ ```
105
+ minify-js path/to/your/directory
106
+ ```
98
107
 
99
- - Specify both **input and output** directories (outputs to `output_folder/`):
108
+ Minify a **specific file** (outputs to `path/to/your/min/file.min.js`):
100
109
 
101
- ```
102
- minify-js input_folder output_folder
103
- ```
110
+ ```
111
+ minify-js path/to/your/file.js
112
+ ```
113
+
114
+ Specify both **input and output** directories (outputs to `output_folder/`):
115
+
116
+ ```
117
+ minify-js input_folder output_folder
118
+ ```
119
+
120
+ ## 🔌 API Reference
121
+
122
+ You can load **minify.js** in your app like this:
123
+
124
+ ```js
125
+ const minifyJS = require('@adamlui/minify.js');
126
+ ```
127
+
128
+ There is a single high level function, `minify(input, options)`, which will perform all minification/recursion phases in a configurable manner that adapts to the string input.
129
+
130
+ ### minify(options)
131
+
132
+ Options are boolean (set to `true` by default) passed as object properties e.g. `minifyJS.minify(input, { option: true })`:
133
+
134
+ ```
135
+ recursive Recursively search for nested files if dir path passed.
136
+ verbose Show logging in console/terminal.
137
+ ```
138
+
139
+ ### minify(input)
140
+
141
+ Input is a string that represents either source code or a path.
142
+
143
+ If **source code** is passed, it is directly minified, then an object containing `srcPath` + `code` + `error` is returned:
144
+
145
+ ```js
146
+ const srcCode = 'function add(first, second) { return first + second; }',
147
+ result = minifyJS.minify(srcCode);
148
+ console.log(result.error); // runtime error, or `undefined` if no error
149
+ console.log(result.code); // minified output: function add(n,d){return n+d}
150
+ ```
151
+
152
+ If a **file path** is passed, the file's code is loaded then minified, returning an object like above.
153
+
154
+ If a **directory path** is passed, JavaScript files are searched for (recursively by default), each is minified, then an array of objects containing `srcPath` + `code` + `error` is returned:
155
+
156
+ ```js
157
+ const recursiveResults = minifyJS.minify('.');
158
+ recursiveResults.forEach(result =>
159
+ console.log(result.srcPath) // JS files in all sub-directories
160
+ );
161
+
162
+ const nonRecursiveResults = minifyJS.minify('.', { recursive: false });
163
+ nonRecursiveResults.forEach(result =>
164
+ console.log(result.srcPath) // JS files in working directory only
165
+ );
166
+ ```
104
167
 
105
168
  <br>
106
169
 
package/minify.js CHANGED
@@ -5,14 +5,8 @@ const fs = require('fs'),
5
5
  path = require('path'),
6
6
  uglifyJS = require('uglify-js');
7
7
 
8
- // Init UI colors
9
- const nc = '\x1b[0m', // no color
10
- br = '\x1b[1;91m', // bright red
11
- by = '\x1b[1;33m', // bright yellow
12
- bg = '\x1b[1;92m'; // bright green
13
-
14
- // Load FLAG settings
15
- const config = {
8
+ // Load FLAGS
9
+ const config = require.main !== module ? {} : {
16
10
  dryRun: process.argv.some(arg => /^--?(?:n|dry-?run)$/.test(arg)),
17
11
  includeDotFolders: process.argv.some(arg =>
18
12
  /^--?(?:dd?|(?:include-?)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?)$/.test(arg)),
@@ -21,130 +15,186 @@ const config = {
21
15
  quietMode: process.argv.some(arg => /^--?q(?:uiet)?$/.test(arg))
22
16
  };
23
17
 
24
- // Show HELP screen if -h or --help passed
25
- if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
26
-
27
- printHelp(`\n${by}minify-js [inputPath] [outputPath] [options]${nc}`);
28
- printHelp('\nPath arguments:');
29
- printHelp(' [inputPath] '
30
- + 'Path to JS file or directory containing JS files to be minified,'
31
- + ' relative to the current working directory.');
32
- printHelp(' [outputPath] '
33
- + 'Path to file or directory where minified files will be stored,'
34
- + ' relative to original file location (if not provided, min/ is used).');
35
- printHelp('\nConfig options:');
36
- printHelp(' -n, --dry-run Don\'t actually minify the file(s),'
37
- + ' just show if they will be processed.');
38
- printHelp(' -d, --include-dotfolders Include dotfolders in file search.');
39
- printHelp(' -D, --include-dotfiles Include dotfiles in file search.');
40
- printHelp(' -q, --quiet Suppress all logging except errors.');
41
- printHelp('\nInfo commands:');
42
- printHelp(' -h, --help Display this help screen.');
43
- printHelp(' -v, --version Show version number.');
44
-
45
- // Show VERSION number if -v or --version passed
46
- } else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
47
- console.info('v' + require('./package.json').version);
48
-
49
- } else { // run MAIN routine
50
-
51
- // Init I/O args
52
- const [inputArg = '', outputArg = ''] = ( // default to empty strings for error-less handling
53
- process.argv.slice(2) // exclude executable and script paths
54
- .filter(arg => !arg.startsWith('-')) // exclude flags
55
- .map(arg => arg.replace(/^\/*/, '')) // clean leading slashes to avoid parsing system root
56
- );
57
-
58
- // Validate input arg (output arg can be anything)
59
- const inputPath = path.resolve(process.cwd(), inputArg);
60
- if (inputArg && !fs.existsSync(inputPath)) {
61
- console.error(`\n${br}Error: First arg must be an existing file or directory.`
62
- + `\n${ inputPath } does not exist.${nc}`
63
- + `\n\n${bg}Example valid command: \n>> minify-js . output.min.js${nc}`
64
- + `\n\n${by}For all command options: \n>> minify-js --help${nc}`);
65
- process.exit(1);
18
+ // Define MAIN functions
19
+
20
+ function findJSfiles(dir, options = { recursive: true, verbose: false }) {
21
+ const dirFiles = fs.readdirSync(dir), unminnedJSfiles = [];
22
+ dirFiles.forEach(file => {
23
+ const filePath = path.resolve(dir, file);
24
+ if (fs.statSync(filePath).isDirectory() && file != 'node_modules' &&
25
+ (config.includeDotFolders || !file.startsWith('.')) && options.recursive) {
26
+ if (options.verbose)
27
+ console.info(`Searching for unminified JS files in: ${filePath}...`);
28
+ unminnedJSfiles.push( // recursively find unminified JS in eligible dir
29
+ ...findJSfiles(filePath));
30
+ } else if (/\.js(?<!\.min\.js)$/.test(file) &&
31
+ (config.includeDotFiles || !file.startsWith('.')))
32
+ unminnedJSfiles.push(filePath); // store eligible unminified JS file for minification
33
+ });
34
+ return unminnedJSfiles;
35
+ }
36
+
37
+ function minify(input, options = { recursive: true, verbose: true }) {
38
+ if (typeof input !== 'string')
39
+ return console.error('minify.js >> ERROR:'
40
+ + ' First argument must be a string of source code or filepath');
41
+ if (fs.existsSync(input)) { // minify based on path arg
42
+ if (input.endsWith('.js')) { // file path passed
43
+ if (options.verbose) console.info(`Minifying ${ input }...`);
44
+ const result = uglifyJS.minify(fs.readFileSync(input, 'utf8'));
45
+ if (result.error) console.error(`ERROR: ${ result.error.message }`);
46
+ return { code: result.code, srcPath: input, error: result.error };
47
+ } else { // dir path passed
48
+ const unminnedJSfiles = findJSfiles(input, { recursive: options.recursive });
49
+ const minifiedJSfiles = unminnedJSfiles.map(jsPath => {
50
+ if (options.verbose) console.info(`Minifying ${ jsPath }...`);
51
+ const srcCode = fs.readFileSync(jsPath, 'utf8'),
52
+ result = uglifyJS.minify(srcCode).code;
53
+ if (result.error) console.error(`ERROR: ${ result.error.message }`);
54
+ return { code: result.code, srcPath: jsPath, error: result.error };
55
+ }).filter(file => file !== null); // filter out failed minifications
56
+ return minifiedJSfiles;
57
+ }
58
+ } else { // minify based on src code arg
59
+ if (options.verbose) console.info('Minifying passed source code...');
60
+ const result = uglifyJS.minify(input);
61
+ if (result.error) console.error(`ERROR: ${ result.error.message }`);
62
+ return { code: result.code, srcPath: input, error: result.error };
66
63
  }
64
+ }
67
65
 
68
- // Recursively find all eligible JavaScript files or arg-passed file
69
- const unminnedJSfiles = [];
70
- if (inputArg.endsWith('.js')) unminnedJSfiles.push(inputPath);
71
- else (function findUnminnedJSfiles(dir) {
72
- const files = fs.readdirSync(dir);
73
- files.forEach(file => {
74
- const filePath = path.resolve(dir, file);
75
- if (fs.statSync(filePath).isDirectory() && file != 'node_modules' &&
76
- (config.includeDotFolders || !file.startsWith('.')))
77
- findUnminnedJSfiles(filePath); // recursively find unminified JS in eligible dir
78
- else if (/\.js(?<!\.min\.js)$/.test(file) &&
79
- (config.includeDotFiles || !file.startsWith('.')))
80
- unminnedJSfiles.push(filePath); // store eligible unminified JS file for minification
81
- });
82
- })(inputPath);
66
+ // EXPORT functions if script was required
67
+ if (require.main !== module) module.exports = { minify, findJSfiles };
68
+
69
+ else { // run as CLI tool
70
+
71
+ // Init UI colors
72
+ const nc = '\x1b[0m', // no color
73
+ br = '\x1b[1;91m', // bright red
74
+ by = '\x1b[1;33m', // bright yellow
75
+ bg = '\x1b[1;92m'; // bright green
76
+
77
+ // Show HELP screen if -h or --help passed
78
+ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
79
+
80
+ printHelp(`\n${by}minify-js [inputPath] [outputPath] [options]${nc}`);
81
+ printHelp('\nPath arguments:');
82
+ printHelp(' [inputPath] '
83
+ + 'Path to JS file or directory containing JS files to be minified,'
84
+ + ' relative to the current working directory.');
85
+ printHelp(' [outputPath] '
86
+ + 'Path to file or directory where minified files will be stored,'
87
+ + ' relative to original file location (if not provided, min/ is used).');
88
+ printHelp('\nConfig options:');
89
+ printHelp(' -n, --dry-run Don\'t actually minify the file(s),'
90
+ + ' just show if they will be processed.');
91
+ printHelp(' -d, --include-dotfolders Include dotfolders in file search.');
92
+ printHelp(' -D, --include-dotfiles Include dotfiles in file search.');
93
+ printHelp(' -q, --quiet Suppress all logging except errors.');
94
+ printHelp('\nInfo commands:');
95
+ printHelp(' -h, --help Display this help screen.');
96
+ printHelp(' -v, --version Show version number.');
97
+
98
+ // Show VERSION number if -v or --version passed
99
+ } else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
100
+ console.info('v' + require('./package.json').version);
101
+
102
+ } else { // run MAIN routine
103
+
104
+ // Init I/O args
105
+ const [inputArg = '', outputArg = ''] = ( // default to empty strings for error-less handling
106
+ process.argv.slice(2) // exclude executable and script paths
107
+ .filter(arg => !arg.startsWith('-')) // exclude flags
108
+ .map(arg => arg.replace(/^\/*/, '')) // clean leading slashes to avoid parsing system root
109
+ );
110
+
111
+ // Validate input arg (output arg can be anything)
112
+ const inputPath = path.resolve(process.cwd(), inputArg);
113
+ if (inputArg && !fs.existsSync(inputPath)) {
114
+ console.error(`\n${br}Error: First arg must be an existing file or directory.`
115
+ + `\n${ inputPath } does not exist.${nc}`
116
+ + `\n\n${bg}Example valid command: \n>> minify-js . output.min.js${nc}`
117
+ + `\n\n${by}For all command options: \n>> minify-js --help${nc}`);
118
+ process.exit(1);
119
+ }
120
+
121
+ // Recursively find all eligible JavaScript files or arg-passed file
122
+ const unminnedJSfiles = inputArg.endsWith('.js') ? [inputPath] : findJSfiles(inputPath);
83
123
 
84
- if (unminnedJSfiles.length === 0) { // print nothing found
85
- printIfNotQuiet(`\n${by}No unminified JavaScript files found.${nc}`);
124
+ if (unminnedJSfiles.length === 0) { // print nothing found
125
+ printIfNotQuiet(`\n${by}No unminified JavaScript files found.${nc}`);
86
126
 
87
- } else if (config.dryRun) { // print files to be processed
88
- console.info(`\n${by}JS files to be minified:${nc}`);
89
- unminnedJSfiles.forEach(file => console.info(file));
127
+ } else if (config.dryRun) { // print files to be processed
128
+ console.info(`\n${by}JS files to be minified:${nc}`);
129
+ unminnedJSfiles.forEach(file => console.info(file));
90
130
 
91
- } else { // actually minify JavaScript files
131
+ } else { // actually minify JavaScript files
132
+ printIfNotQuiet(''); // line break before first log
92
133
 
93
- let minifiedCnt = 0;
94
- printIfNotQuiet(''); // line break before first log
95
- unminnedJSfiles.forEach(jsPath => {
96
- printIfNotQuiet(`Minifying ${ jsPath }...`);
97
- try { // to minify JS file
134
+ // Build array of minified code
135
+ const failedJSpaths = [];
136
+ const minifiedJSdata = unminnedJSfiles.map(jsPath => {
137
+ const result = minify(jsPath, { verbose: !config.quietMode });
138
+ if (result.error) failedJSpaths.push(jsPath);
139
+ return result;
140
+ }).filter(result => !result.error); // filter out failed minifications
141
+
142
+ // Write array data to files
143
+ minifiedJSdata.forEach(({ code, srcPath }) => {
98
144
  const outputDir = path.join(
99
- path.dirname(jsPath), // path of file to be minified
100
- /so?u?rce?$/.test(path.dirname(jsPath)) ? '../min' // + ../min/ if in *(src|source)/
145
+ path.dirname(srcPath), // path of file to be minified
146
+ /so?u?rce?$/.test(path.dirname(srcPath)) ? '../min' // + ../min/ if in *(src|source)/
101
147
  : outputArg.endsWith('.js') ? path.dirname(outputArg) // or path from file output arg
102
148
  : outputArg || 'min' // or path from folder output arg or min/ if no output arg passed
103
149
  );
104
150
  const outputFilename = (
105
151
  outputArg.endsWith('.js') && inputArg.endsWith('.js')
106
152
  ? path.basename(outputArg).replace(/(\.min)?\.js$/, '')
107
- : path.basename(jsPath, '.js')
153
+ : path.basename(srcPath, '.js')
108
154
  ) + '.min.js';
109
- const outputPath = path.join(outputDir, outputFilename),
110
- minifiedCode = uglifyJS.minify(fs.readFileSync(jsPath, 'utf8')).code;
155
+ const outputPath = path.join(outputDir, outputFilename);
111
156
  if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
112
- fs.writeFileSync(outputPath, minifiedCode, 'utf8');
113
- minifiedCnt++;
114
- } catch (err) { console.error(`${br}Error minifying ${ jsPath }: ${ err.message }${nc}`); }
115
- });
116
-
117
- // Print final summary
118
- if (minifiedCnt) {
119
- printIfNotQuiet(`\n${bg}Minification complete!${nc}`);
120
- printIfNotQuiet(`${ minifiedCnt } file${ minifiedCnt > 1 ? 's' : '' } minified.`);
121
- } else printIfNotQuiet(`${by}No unminified JavaScript files processed successfully.${nc}`);
157
+ fs.writeFileSync(outputPath, code, 'utf8');
158
+ });
159
+
160
+ // Print final summary
161
+ if (minifiedJSdata.length > 0) {
162
+ printIfNotQuiet(`\n${bg}Minification complete!${nc}`);
163
+ printIfNotQuiet(
164
+ `${ minifiedJSdata.length } file${ minifiedJSdata.length > 1 ? 's' : '' } minified.`);
165
+ } else printIfNotQuiet(`${by}No unminified JavaScript files processed successfully.${nc}`);
166
+ const failedCnt = unminnedJSfiles.length - minifiedJSdata.length;
167
+ if (failedCnt > 0) {
168
+ printIfNotQuiet(`\n${br + failedCnt} file${ failedCnt > 1 ? 's' : '' } failed to minify:${nc}`);
169
+ printIfNotQuiet(failedJSpaths.join(', '));
170
+ }
171
+ }
122
172
  }
123
- }
124
173
 
125
- // Define LOGGING functions
126
-
127
- function printHelp(msg) { // wrap msg + indent 2nd+ lines (for --help screen)
128
- const terminalWidth = process.stdout.columns || 80,
129
- indentation = 29, lines = [], words = msg.match(/\S+|\s+/g);
174
+ // Define LOGGING functions
175
+
176
+ function printHelp(msg) { // wrap msg + indent 2nd+ lines (for --help screen)
177
+ const terminalWidth = process.stdout.columns || 80,
178
+ indentation = 29, lines = [], words = msg.match(/\S+|\s+/g);
179
+
180
+ // Split msg into lines of appropriate lengths
181
+ let currentLine = '';
182
+ words.forEach(word => {
183
+ const lineLength = terminalWidth - ( lines.length === 0 ? 0 : indentation );
184
+ if (currentLine.length + word.length > lineLength) { // cap/store it
185
+ lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
186
+ currentLine = '';
187
+ }
188
+ currentLine += word;
189
+ });
190
+ lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
130
191
 
131
- // Split msg into lines of appropriate lengths
132
- let currentLine = '';
133
- words.forEach(word => {
134
- const lineLength = terminalWidth - ( lines.length === 0 ? 0 : indentation );
135
- if (currentLine.length + word.length > lineLength) { // cap/store it
136
- lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
137
- currentLine = '';
138
- }
139
- currentLine += word;
140
- });
141
- lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
192
+ // Print formatted msg
193
+ lines.forEach((line, index) => console.info(
194
+ index === 0 ? line // print 1st line unindented
195
+ : ' '.repeat(indentation) + line // print subsequent lines indented
196
+ ));
197
+ }
142
198
 
143
- // Print formatted msg
144
- lines.forEach((line, index) => console.info(
145
- index === 0 ? line // print 1st line unindented
146
- : ' '.repeat(indentation) + line // print subsequent lines indented
147
- ));
199
+ function printIfNotQuiet(msg) { if (!config.quietMode) console.info(msg); }
148
200
  }
149
-
150
- function printIfNotQuiet(msg) { if (!config.quietMode) console.info(msg); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/minify.js",
3
- "version": "1.2.4",
3
+ "version": "1.3.0",
4
4
  "description": "Recursively minify all JavaScript files",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -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
- &nbsp;简体中文 |
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
- 本软件『按原样』提供,不提供任何形式的明示或保证暗示的,包括但不限于适销性保证,适用于特定目的和非侵权。 在任何情况下都不得作者或版权持有人对任何索赔、损害或其他责任,无论是在合同、侵权或其他方面的行为中,由以下原因引起,出于或与软件或使用或其他交易有关软件。
@@ -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
- &nbsp;简体中文 |
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>
@@ -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
- &nbsp;简体中文 |
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> 并等待回复后再公开。
@@ -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
- &nbsp;繁體中文 |
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
- 本軟體『依現況』提供,不提供任何形式的明示或保證暗示的,包括但不限於適銷性保證,適用於特定目的和非侵權。 在任何情況下都不得作者或版權持有人對任何索賠、損害或其他責任,無論是在合約、侵權或其他方面的行為中,由以下原因引起,出於或與軟體或使用或其他交易有關軟體。
@@ -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
- &nbsp;繁體中文 |
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>
@@ -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
- &nbsp;繁體中文 |
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> 並等待回復後再公開。