WebPack自动吐出脚本

时间:2024-03-14 22:40:38

window.c = c;
window.res = "";
window.flag = false;

c = function (r) {
    if (flag) {
        window.res = window.res + `"${r.toString()}"` + ":" + (e[r] + "") + ",";
    }
    return window.c(r);
}

代码改进了一下,可以过滤掉重复的方法

window.c = c;
window.res = "";
window.flag = false;
window.addedMethods = {};

c = function (r) {
    if (flag) {
        if (!window.addedMethods[r]) {
            window.res = window.res + `"${r.toString()}"` + ":" + (e[r] + "") + ",";
            window.addedMethods[r] = true;
        }
    }
    return window.c(r);
}

生成的方法中如果有注释会影响执行,搜索/**删了就行