Recursively minify all JavaScript files.
npm install @adamlui/minify.js

As a global utility:
```
$ npm install -g @adamlui/minify.js
As a dev dependency (e.g. for build scripts), from your project root:
``
$ npm install -D @adamlui/minify.js
As a runtime dependency (e.g. for on-the-fly minification), from your project root:
``
$ npm install @adamlui/minify.js

The basic global command is:
``
$ minify-js
📝 Note: Pass -n or --dry-run to only see what files will be processed.
#
To specify input/output paths:
``
$ minify-js [input_path] [output_path]
- [input_path]: Path to JS file or directory containing JS files to be minified, relative to the current working directory.[output_path]
- : Path to file or directory where minified files will be stored, relative to input root (if not provided, min/ is used).
📝 Note: If folders are passed, files will be processed recursively unless -R or --no-recursion is passed.
#
To use as a package script, in your project's package.json:
`json`
"scripts": {
"build:js": "
},
Replace with minify-js + optional args. Then, npm run build:js can be used to run the command.
#
Minify all JavaScript files in the current directory (outputs to min/):
``
$ minify-js
Minify all JavaScript files in a specific directory (outputs to min/path/to/your/directory/):
``
$ minify-js path/to/your/directory
Minify a specific file (outputs to min/path/to/your/file.min.js):
``
$ minify-js path/to/your/file.js
Specify both input and output directories (outputs to output_folder/):
``
$ minify-js input_folder output_folder
#
`
Boolean options:
-n, --dry-run Don't actually minify the file(s),
just show if they will be processed.
-d, --include-dotfolders Include dotfolders in file search.
-D, --include-dotfiles Include dotfiles in file search.
-R, --no-recursion Disable recursive file searching.
-M, --no-mangle Disable mangling names.
-X, --no-filename-change Disable changing file extension to .min.js
-i, --rewrite-imports Update import paths from .js to .min.js
-c, --copy Copy minified code to clipboard instead
of writing to file if single source file
is processed.
-r, --relative-output Output files relative to each source file instead of to input root.
-q, --quiet Suppress all logging except errors.
Parameter options:
--ignores="dir/,file1.js,file2.js" Files/directories to exclude from minification.
--comment="comment" Prepend header comment to minified code.
Separate by line using '\n'.
--config="path/to/file" Load custom config file.
Commands:
--init Create config file (in project root).
-h, --help Display help screen.
-v, --version Show version number.
`
#
minify.js can be customized using a minify.config.mjs or minify.config.js placed in your project root.
Example defaults:
`js`
export default {
dryRun: false, // don't actually minify the file(s), just show if they will be processed
includeDotFolders: false, // include dotfolders in file search
includeDotFiles: false, // include dotfiles in file search
noRecursion: false, // disable recursive file searching
noMangle: false, // disable mangling names
noFilenameChange: false, // disable changing file extension to .min.js
rewriteImports: false, // update import paths from .js to .min.js
copy: false, // copy minified code to clipboard instead of write to file if single file processed
relativeOutput: false, // output files relative to each src file instead of to input root
quietMode: false, // suppress all logging except errors
ignores: '', // files/dirs to exclude from minification
comment: '' // header comment to prepend to minified code
}
💡 Run minify-js init to generate a template minify.config.mjs in your project root.

You can also import minify.js into your app to use its API methods, both as an ECMAScript module or a CommonJS module.
#### ESM*:
`js`
import minifyJS from '@adamlui/minify.js'
#### CJS:
`js`
const minifyJS = require('@adamlui/minify.js')
###### _*Node.js version 14 or higher required_
#
💡 Minifies JavaScript code based on the string input supplied.
If source code is passed, it is directly minified, then an object containing srcPath + code + error is returned:
`js
const srcCode = 'function add(first, second) { return first + second }',
minifyResult = minifyJS.minify(srcCode)
console.log(minifyResult.error) // outputs runtime error, or undefined if no error`
console.log(minifyResult.code) // outputs minified JS: 'function add(n,d){return n+d}'
If a file path is passed, the file's code is loaded then minified, returning an object like above.
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:
`js
// Outputs paths to source JS files in working directory + all nested directories
const minifyResults = minifyJS.minify('.')
minifyResults.forEach(result => console.log(result.srcPath))
// Outputs minified code of 2nd JS file if found, or undefined if not found`
console.log(minifyResults[1].code)
Options are boolean, passed as object properties. For example:
`jsinput
// Returns array of data objects where dotfiles are also processed if is a path`
minifyJS.minify(input, { dotFiles: true })
Available parameters (and their default settings) are:
Name | Type | Desciption | Default value
-----------------|---------|--------------------------------------------------------------------------|---------------
recursive | Boolean | Recursively search for nested files if dir path passed. | trueverbose | Boolean | Show logging in console/terminal. | truedotFolders | Boolean | Include dotfolders in file search. | falsedotFiles | Boolean | Include dotfiles in file search. | falsemangle | Boolean | Shorten variable names (typically to one character). | truerewriteImports | Boolean | Update import paths from .js to .min.js | falserelativeOutput | Boolean | Output files relative to each source file instead of to input root. | falseignores | Array | Files/dirs to exclude from minification. | []comment | String | Header comment to prepend to minified code. Separate by line using '\n'. | ''
#
💡 Searches for all unminified JavaScript files within the searchDir string passed (useful for discovering what files minify() will process) and returns an array containing their filepaths.
Options are boolean, passed as object properties. For example:
`js
// Search for unminified JS files in exactly assets/js
const searchResults = minifyJS.findJS('assets/js', { recursive: false })
console.log(searchResults)
/* sample output:
findJS() » Searching for unminified JS files...
findJS() » Search complete! 2 files found.
findJS() » Check returned array.
[
'E:\\js\\utils\\minify.js\\assets\\js\\foo.js',
'E:\\js\\utils\\minify.js\\assets\\js\\bar.js'
]
*/
`
Available parameters (and their default settings) are:
Name | Type | Desciption | Default value
--------------|---------|----------------------------------------------------------|---------------
recursive | Boolean | Recursively search for nested files in searchDir passed. | trueverbose | Boolean | Show logging in console/terminal. | truedotFolders | Boolean | Include dotfolders in file search. | falsedotFiles | Boolean | Include dotfiles in file search. | falseignores | Array | Files/dirs to exclude from search results. | []`

Copyright © 2023–2026 Adam Lui & contributors.
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.

> Gulp plug-in to recursively minify all JavaScript files.
Install /
Readme /
Discuss
> Recursively compile all SCSS files into minified CSS.
Install /
Readme /
CLI usage /
API usage /
Discuss
