Currently, I am using Vite
with ReactJS
and have the following two types of comments inside my codes, for example:
export const Main = () => {
useEffect(() => {
// console.log("first type of comment.");
}, [])
return (
<>
{/* <div>Second type of comment.</div> */}
</>
);
}
Will these two types of comments be visible in client browsers, if I use vite
and vite build
, respectively?
For similar issues, How comment a JSP expression? talks about whether the comments will be visible in client browsers, but it is for JSP
type of comments.
2
Answers
It depends on build process. When you run a prod build – vite build, it initiates a minification process and strips of both style of comments
//javascript comment
, and{/* <div>JSX comment</div> */}
So, rest assured, when you run vite build, both types of comments will be removed, and they won’t be visible to the users in their browsers.
You can configure esbuild in vite to remove things like ‘console’, ‘debugger’ before putting it into production, here if you want to remove comment lines (including JavaScript comments and JSX comments) you can add terser plugin to vite config to remove that when building.