https://github.com/montasim/terser-minify-tool
This script processes files within a project directory by minifying JavaScript files and copying other file types to a specified output directory. It leverages the Terser library for minification and tracks the size reduction achieved, reporting in kilobytes.
https://github.com/montasim/terser-minify-tool
build-tool compression file-processing minification resource-optimization terser web-optimization
Last synced: about 1 year ago
JSON representation
This script processes files within a project directory by minifying JavaScript files and copying other file types to a specified output directory. It leverages the Terser library for minification and tracks the size reduction achieved, reporting in kilobytes.
- Host: GitHub
- URL: https://github.com/montasim/terser-minify-tool
- Owner: montasim
- License: mit
- Created: 2024-06-26T03:46:37.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-24T14:27:15.000Z (almost 2 years ago)
- Last Synced: 2025-02-09T20:36:44.933Z (over 1 year ago)
- Topics: build-tool, compression, file-processing, minification, resource-optimization, terser, web-optimization
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Terser Minify Tool đ
This script processes files within a project directory by minifying JavaScript files and copying other file types to a specified output directory. It leverages the Terser library for minification and tracks the size reduction achieved, reporting in kilobytes.
## Table of Contents
1. [Features](#features-)
2. [Prerequisites](#prerequisites-)
3. [Setup](#setup-)
4. [Running the Script](#running-the-script-)
5. [Output](#output-)
6. [Error Handling](#error-handling-)
7. [Contributing](#contributing-)
8. [License](#license-)
9. [Author](#author-)
10. [Contributors](#contributors-)
11. [Contact](#contact-)
12. [Acknowledgments](#acknowledgments-)
## Features đ
- **Minification of JavaScript Files**: Uses Terser to minify `.js` files, improving loading times and reducing bandwidth consumption.
- **File Copying**: Copies non-JavaScript files from the source directory to the output directory, preserving their original structure.
- **Size Tracking**: Reports the original and minified sizes of JavaScript files to help you understand the impact of minification.
- **Custom Configuration**: Allows specifying ignore patterns and other configurations through a `build.json` file.
## Prerequisites đ
Before you run this script, ensure you have the following installed:
- [Node.js](https://nodejs.org/en/download/) (version 12 or higher is recommended)
- [Yarn](https://yarnpkg.com/) (version 1.22 or higher is recommended)
## Setup đ§
1. **Clone the Repository**: Clone or download the repository to your local machine.
```bash
git clone https://github.com/montasim/terser-minify-tool.git
cd terser-minify-tool
```
2. **Install Dependencies**: Run the following command in the root directory of your project to install necessary dependencies.
```bash
yarn install
```
3. **Configuration File**: Modify the `build.json` file in the root directory to set up your specific configurations.
```json
{
"parse": {
"ecma": 8
},
"compress": {
"ecma": 5,
"warnings": false,
"arrows": false,
"collapse_vars": false,
"comparisons": false,
"computed_props": false,
"hoist_funs": false,
"hoist_props": false,
"hoist_vars": false,
"inline": false,
"loops": false,
"negate_iife": false,
"properties": false,
"reduce_funcs": false,
"reduce_vars": false,
"switches": false,
"toplevel": false,
"typeofs": false,
"booleans": true,
"if_return": true,
"sequences": true,
"unused": true,
"conditionals": true,
"dead_code": true,
"evaluate": true
},
"mangle": {
"safari10": true
},
"output": {
"ecma": 5,
"comments": false,
"ascii_only": true
}
}
```
## Running the Script đ
To run the script, execute the following command in the root directory of your project:
```bash
yarn build
```
## Output đ
The script outputs one table:
- Displays the total number of files processed:
- how many were minified,
- how many were copied,
- how many failed,
- the total original size,
- minified sizes after processed.

## Error Handling đ ī¸
If there are issues during file processing, errors will be logged to the console, specifying which files could not be processed and the nature of the error.
## Contributing đ¤
Contributions to this script are welcome. Please fork the repository and submit a pull request with your enhancements.
## License đ
This script is provided under the MIT License. See the [LICENSE](LICENSE) file for more details.
## Author đ
## Contributors đĨ
[](https://badges.pufler.dev)
## Contact đŦ
If you have any suggestions or encounter issues, please open an [issue](https://github.com/montasim/terser-minify-tool/issues) on the [GitHub repository page](https://github.com/montasim/terser-minify-tool).
## Acknowledgments đ
1. [jrschumacher - terser script gist](https://gist.github.com/jrschumacher/943929c81e59a75b59f2eb849addcbf7)