在这个项目中,我使用的是吞咽版本3.0.1,我希望在输出中保留包含许可文本的注释。
在项目页面上,有这样的说法:
Most of the minify options from the UglifyJS API are supported.在UglifyJS自述中,声明为了保存许可文本
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 found 这里,但这只会生成:
[13:37:42] GulpUglifyError: unable to minify JavaScript
Caused by: DefaultsError: `preserveComments` is not a supported option有没有办法通过命令行参数插件实现gulp-uglify的建议?如果不可能,我可以使用webpack插件吗?
可以通过指定这个解决办法来实现雷杰普,但如果可能的话,我希望直接从UglifyJS中使用该功能。此外,它也不保持这样的许可证头。
发布于 2020-12-16 19:34:32
我也有同样的问题。我注意到UglifyJS注释文档建议
您可以传递
--comments all以保存所有注释,也可以传递一个有效的JavaScript regexp来保存与该regexp匹配的注释。例如,--comments /^!/将保留像/*! Copyright Notice */这样的注释。
所以我试了一下"comments: /^!/":
.pipe(uglify({
mangle: true,
output: {
beautify: true,
comments: /^!/
}
}))我现在看到的版权评论在由此产生的丑陋代码。
https://stackoverflow.com/questions/53853402
复制相似问题