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.
- Features
- Prerequisites
- Setup
- Running the Script
- Output
- Error Handling
- Contributing
- License
- Author
- Contributors
- Contact
- Acknowledgments
- 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.
Before you run this script, ensure you have the following installed:
-
Clone the Repository: Clone or download the repository to your local machine.
git clone https://github.com/montasim/terser-minify-tool.git cd terser-minify-tool
-
Install Dependencies: Run the following command in the root directory of your project to install necessary dependencies.
yarn install
-
Configuration File: Modify the
build.json
file in the root directory to set up your specific configurations.{ "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 } }
To run the script, execute the following command in the root directory of your project:
yarn build
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.
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.
Contributions to this script are welcome. Please fork the repository and submit a pull request with your enhancements.
This script is provided under the MIT License. See the LICENSE file for more details.
๏ผญโข๏ผฎ๏ผดฮ๏ผณ๏ผฉ๏ผญ |
If you have any suggestions or encounter issues, please open an issue on the GitHub repository page.