question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTML comments being removed on build

See original GitHub issue

🐛 bug report

🎛 Configuration (.babelrc, package.json, cli command)

parcel build ./index.html --out-dir dist/static --public-url /static

🤔 Expected Behavior

HTML comments should stay inside the outputed index.html file.

😯 Current Behavior

All comments are removed from this file.

💁 Possible Solution

Not so much a solution but a workaround. Could use plain strings instead of comments.

🔦 Context

I’m trying to server-side render a ReactJS application which I would replace HTML comment with the server-generated HTML. I realise I could use a string like ‘replace-me’ but it seems a hack around and may get messy down the road.

💻 Code Sample

<!DOCTYPE html>
<html>

<head>
	<title>My react app</title>
	<script defer src='./src/client/index.tsx'></script>
	<style>body { margin: 0 }</style>
	<!-- HEAD -->
</head>

<body>
	<div id="app"><!-- BODY --></div>
</body>
</html>

🌍 Your Environment

Software Version(s)
Parcel 1.12.3
Node 10.16.3
npm/Yarn 1.17.3 (Yarn)
Operating System MacOS Mojave (10.14.6)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
HenryBrown0commented, Sep 20, 2019

My apologies, this was a caching issue. Deleting my cache and trying this worked great.

I’ll reopen my issue on docs as I haven’t seen this on the website

0reactions
mischniccommented, Sep 20, 2019

Works for me: https://github.com/mischnic/parcel-issue-3535-htmlnano-comment with this output:

<!DOCTYPE html><html><head><title>My react app</title><style>body{margin:0}</style><!-- HEAD --></head><body> <div id="app"><!-- BODY --></div> </body></html>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack remove HTML comments on production build
to remove comments in html in production mode, you need the plugin, HtmlWebpackPlugin, in the Minification option put removeComments: true, ...
Read more >
Hiding/Unhiding Items With HTML Comments
Commenting out items is useful when you don't want to completely delete something. Using HTML comments will let you add or remove...
Read more >
How to Comment & Comment Out in HTML - HubSpot Blog
Comments can help you explain, organize, and debug your code. Learn how to add them in your HTML so you code faster and...
Read more >
How to Remove HTML Comments from the Page Source
There's more than one way to remove these comments, and, in some cases, the best solution is to stop them being created in...
Read more >
gatsby-remark-remove-comments
By default, in Remark, HTML comments in Markdown will appear in the output, this plugin removes them. For the following Markdown file: #...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found