Webpack 将UglifyJS2与gulp插件一起使用时保留许可证注释

Webpack 将UglifyJS2与gulp插件一起使用时保留许可证注释,webpack,gulp,uglifyjs,gulp-uglify,uglifyjs2,Webpack,Gulp,Uglifyjs,Gulp Uglify,Uglifyjs2,在这个项目中,我使用的是3.0.1版,我希望在输出中保留包含许可证文本的注释 在项目页面上,说明 Most of the minify options from the UglifyJS API are supported. 并显示如何传递到插件 在本手册中,规定为了保存许可证文本 You can pass --comments to retain certain comments in the output. By default it will keep JSDoc-style comme

在这个项目中,我使用的是3.0.1版,我希望在输出中保留包含许可证文本的注释

在项目页面上,说明

Most of the minify options from the UglifyJS API are supported.
并显示如何传递到插件

在本手册中,规定为了保存许可证文本

You can pass --comments to retain certain comments in the output. By default it will keep JSDoc-style comments that contain "@preserve", "@license" or "@cc_on" (conditional compilation for IE)
所以我试着:

.pipe(uglify({
    mangle: true,
    output: {
        beautify: true,
        comments: "all"
    }
}))
但是,由于即使指定
“all”
也不会导致许可证属性注释,因此我假设minify选项
comments
的行为与命令行参数
--comments
不同

我还尝试了找到的
preserveComments
,但这只会生成:

[13:37:42] GulpUglifyError: unable to minify JavaScript
Caused by: DefaultsError: `preserveComments` is not a supported option
有没有办法通过
gulp uglify
插件实现建议?如果不可能,我可以使用


这是通过指定来实现的,但是如果可能的话,我想直接使用UglifyJS的功能。此外,它也不会像那样保留许可证标题。

我也有同样的问题。我注意到你的建议

您可以传递
--comments all
以保留所有注释,或者传递有效的JavaScript regexp以仅保留与此regexp匹配的注释。例如
--comments/^/
将保留类似
/*的注释!版权声明*/

所以我尝试了“
注释:/^!/
”:

现在,我在生成的丑陋代码中看到了版权注释。

。所以它应该像你描述的那样工作。考虑将此报告为bug。
.pipe(uglify({
    mangle: true,
    output: {
        beautify: true,
        comments: /^!/
    }
}))