我在 React 应用程序中有以下 JSX:
render() {
return (
<div>
{/* A JSX comment */}
</div>
)
}
我正在使用 webpack 来编译和缩小代码。
在我的 webpack 插件中,我使用 UglifyJsPlugin 来尝试保留注释:
new webpack.optimize.UglifyJsPlugin( {
compress: {
warnings: false,
// Disabled because of an issue with Uglify breaking seemingly valid code:
// https://github.com/facebookincubator/create-react-app/issues/2376
// Pending further investigation:
// https://github.com/mishoo/UglifyJS2/issues/2011
comparisons: false,
},
mangle: {
safari10: true,
except: ['__', '_n', '_x', '_nx' ],
},
output: {
comments: true,
// Turned on because emoji and regex is not minified properly using default
// https://github.com/facebookincubator/create-react-app/issues/2488
ascii_only: true,
},
extractComments: false,
sourceMap: shouldUseSourceMap,
} ),
comments:true正在保留来自 React 的一些评论,但我来自 JSX 的评论/* A JSX comment */正在从缩小的代码中剥离。如何防止从缩小/生产代码中删除该评论?
还有我打开评论的 Babel module规则:
{
test: /\.(js|jsx|mjs)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
// @remove-on-eject-begin
babelrc: false,
presets: [ require.resolve( 'babel-preset-cgb' ) ],
// @remove-on-eject-end
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: false,
comments: true,
},
},
},