I have the following JSX in a React app:
render() {
return (
<div>
{/* A JSX comment */}
</div>
)
}
I am using webpack to compile and minify the code.
In my webpack plugins I am using UglifyJsPlugin to try and keep the comments:
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
is preserving some comments from React but my comment from JSX /* A JSX comment */
, is being stripped from the minified code. How can I prevent that comment from being stripped out of the minified/production code?
Also my Babel module rule with comments turned on:
{
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,
},
},
},