如何防止 Uglify 在字符串中取消转义“</script”?

How to prevent Uglify un-escaping "</script" in strings?

我有这样的代码:

var string = '<script src="' + src + '">\x3c/script>';

我使用 \x3c 而不是 < 来避免使用结束脚本标记(如果在网络浏览器中用作内联脚本,这会提前结束脚本,破坏所有内容)。

但不幸的是,uglify 将其转换回 < 字符,破坏了我的页面。

看起来 Uglify 有 an option called inline-scripts intended to fix this, but there are no docs on using this option with the API (I'm using it via gulp-uglify 所以我需要能够在选项对象中传递这个选项,而不是通过 CLI。

我该怎么做? None 以下作品:

需要用下划线指定,如下:

options: {{beautify: {'inline_script': true}}}

我知道这是一个老问题,但是给出的答案不正确。你需要在 uglifyjs 中使用 output 对象。

.pipe(uglify({
    output: {
        'inline_script': true
    }
}))