Exclude debug JavaScript code during minification

后端 未结 11 2035
庸人自扰
庸人自扰 2020-11-28 07:16

I\'m looking into different ways to minify my JavaScript code including the regular JSMin, Packer, and YUI solutions. I\'m really interested in the new Google Closure Compil

11条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 07:46

    I haven't looked into minification so far, but this behaviour could be accomplished using a simple regular expression:

    s/;;;.*//g
    

    This replaces everything in a line after (and including) three semicolons with nothing, so it's discarded before minifying. You can run sed (or a similar tool) before running your minification tool, like this:

    sed 's/;;;.*//g' < infile.js > outfile.js
    

    BTW, if you're wondering whether the packed version or the minified version will be 'better', read this comparison of JavaScript compression methods.

提交回复
热议问题