gpt4 book ai didi

javascript - 有没有办法保留许可证评论?

转载 作者:行者123 更新时间:2023-12-01 15:27:16 25 4
gpt4 key购买 nike

我正在使用 babel-loader在我的webpack.config.js文件,但我注意到它删除了表单的许可证注释:

/*! whatever **/

有没有办法保存它们?
我注意到 babel 有一个 comments选项,但我想这会保留 任意 评论,而不仅仅是许可证。
const webpack = require('webpack');

module.exports = {
resolve: {
alias: {
'vue$': 'vue/dist/vue.js'
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
scss: 'vue-style-loader!css-loader!sass-loader',
js: 'babel-loader'
}
}
},
{
test: /\.js$/,
use: {
loader: 'babel-loader',
}
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: false,
}
})
],
};

我已经尝试过:
plugins: [
new webpack.optimize.UglifyJsPlugin({
output:{
comments: true
}
})

以及 comments: '/^!/'comments: /^!/ .
没有任何效果。

如果我删除整个 plugins,它只会保留评论webpack 配置中的选项。

我还尝试使用许可证注释,例如:
/** comments */

/*! comments */

/*! @license comments */

/*! @preserve comments */

最佳答案

那是 bug ,自 2015 年以来一直在 webpack/uglify 中,并且从未得到修复。

他们应该使用 this 修复它而是添加 extractCommentstrue但它仍然不适用于 some people所以一年后的 2019 another PR已经开放据说可以修复它。

new UglifyJSPlugin({
sourceMap: true,
extractComments: true
})

所以这是一个已经存在多年的已知错误。也许黑客确实存在,但这是一般情况。

关于javascript - 有没有办法保留许可证评论?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48408237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com