I have grunt-contrib-uglify minifying a bunch of js files for me, and thought it would be really neat if it could sum up the difference in file sizes before and after minification. Is there any way to do this?

Thanks!

有帮助吗?

解决方案

A simple method would be to write your own task that used the nodejs file system library to list out the sizes of the files you want to compare using fs.Stats. A more complex option would be to log both the pre and post sizes to a file with a timestamp so that they can be tracked and graphed.

Or go to npmjs.org and grab an existing project to use as the base to build on: grunt-size-report

grunt-size-report

Modify your Gruntfile.js to add a section for size_report:

size_report: {
    your_target: {
        files: {
            list: ['path/to/*.html', 'path/to/images/*.jpg']
        },
    },
},

and if you add the size_report call into your list of build commands you'll get:

~~~~~~~~~~~
Size report
~~~~~~~~~~~

Filename                      Size          %
---------------------------------------------
test/testfiles/test4.txt     9.6 KiB    46.8%
test/testfiles/test1.txt     7.0 KiB    34.0%
test/testfiles/test2.txt     3.5 KiB    17.0%
test/testfiles/test3.txt     447 B       2.1%
=============================================
Total:                      20.5 KiB

This report isn't showing % space saved, but if you run it with two separate subtasks on your /app and then your /dist folders you can perform the comparison manually yourself.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top