Skip to content

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.

License

Notifications You must be signed in to change notification settings

montasim/terser-minify-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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
๏ผญโ™ข๏ผฎ๏ผดฮ›๏ผณ๏ผฉ๏ผญ

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

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published