/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.

Primary LanguageJavaScriptMIT LicenseMIT

Terser Minify Tool 🚀

GitHub contributors badge GitHub language count badge GitHub top language badge GitHub code size badge GitHub repo size badge GitHub file count badge GitHub open issues badge GitHub closed issues badge GitHub open pull requests badge GitHub closed pull requests badge GitHub active milestones badge GitHub completed milestones badge GitHub license badge GitHub last commit badge GitHub Discussions badge

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
  2. Prerequisites
  3. Setup
  4. Running the Script
  5. Output
  6. Error Handling
  7. Contributing
  8. License
  9. Author
  10. Contributors
  11. Contact
  12. 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 (version 12 or higher is recommended)
  • Yarn (version 1.22 or higher is recommended)

Setup 🔧

  1. 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
  2. Install Dependencies: Run the following command in the root directory of your project to install necessary dependencies.

    yarn install
  3. 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
      }
    }

Running the Script 🏃

To run the script, execute the following command in the root directory of your project:

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.

output

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 file for more details.

Author 📖

Moon
M♢NTΛSIM

Contributors 👥

Contributors Display

Contact 📬

If you have any suggestions or encounter issues, please open an issue on the GitHub repository page.

Acknowledgments 🙏

  1. jrschumacher - terser script gist