Exclude debug JavaScript code during minification

后端 未结 11 2033
庸人自扰
庸人自扰 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:34

    I am with @marcel-korpel. Isn't perfect but works. Replace the debug instructions before minification. The regular expression works in many places. Watch out unenclosed lines.

    /console\.[^;]*/gm
    

    Works on:

    ;;;     console.log("Starting process");
    console.log("Starting process");
    console.dir("Starting process");;;;;
    console.log("Starting "+(1+2)+" processes"); iamok('good');
    console.log('Message ' +
        'with new line'
    );
    console.group("a");
    console.groupEnd();
    swtich(input){
        case 1 : alert('ok'); break;
        default: console.warn("Fatal error"); break;
    }
    

    Don't works:

    console.log("instruction without semicolon")
    console.log("semicolon in ; string");
    

提交回复
热议问题