Parcel: HTML comments being removed on build

Created on 20 Sep 2019  路  5Comments  路  Source: parcel-bundler/parcel

馃悰 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)

Waiting Question

Most helpful comment

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

All 5 comments

Have you tried adding a .htmlnanorc config with

{
  "removeComments": false
}

?

I have, no luck. Do I need to point to this config anywhere?

Just put the config file next to your package.json

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>

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

Was this page helpful?
0 / 5 - 0 ratings