Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserving HTML comments in the index.html #4245

Closed
thenathanjones opened this issue Apr 3, 2018 · 9 comments
Closed

Preserving HTML comments in the index.html #4245

thenathanjones opened this issue Apr 3, 2018 · 9 comments

Comments

@thenathanjones
Copy link

thenathanjones commented Apr 3, 2018

Hey all,

I'm wondering if there is a way to preserve HTML comments from the public/index.html in the generated HTML when running a build?

I'm trying to avoid ejecting at all costs, so if need be I'm just going to add them back in as a simple script, but it'd be easier if I didn't have to do anything.

Thanks in advance.

Cheers,
Nathan

@iansu
Copy link
Contributor

iansu commented Apr 3, 2018

Why do you need to preserve the comments?

@thenathanjones
Copy link
Author

thenathanjones commented Apr 4, 2018

Hey @iansu, I have some nginx SSI statements I want included in the final HTML. They're implemented as HTML comments.

@iansu
Copy link
Contributor

iansu commented Apr 10, 2018

We currently use the HTML Webpack Plugin to generate index.html so you might want to file an issue with them: https://github.com/jantimon/html-webpack-plugin

@thenathanjones
Copy link
Author

thenathanjones commented Apr 10, 2018

Hey @iansu thanks for the pointer. Looking at the create-react-app configuration, it appears this behaviour is as intended, and there doesn't look like a logical way to change it without ejecting. I guess I'll stick with the post-processing script option.

@iansu
Copy link
Contributor

iansu commented Apr 10, 2018

Ah, you're right, we are removing them intentionally in the production config. I guess the reasoning there is that we've heavily commented our index.html template and there's no reason to ship that to production. That makes it tricky for us to change that setting.

@iansu iansu closed this as completed Apr 10, 2018
@MattSidor
Copy link

MattSidor commented Apr 30, 2018

Hey @thenathanjones, I am trying to accomplish the same thing. Would you mind sharing the post-processing script you used for this?

@thenathanjones
Copy link
Author

thenathanjones commented May 3, 2018

Hey @MattSidor. Sorry on the delay, I've been on leave. I've stuck a version of the script in this gist: https://gist.github.com/thenathanjones/88ccf785826ef880c45d2c89d3b3ce96

Essentially I put an tag in my markup where I want everything and then use awk to replace it with the contents of a file containing my SSI tags. I went with the tag approach as it doesn't render anything when developing, yet because the browser doesn't know what it is, it just ignores it.

It's not pretty, but it has caused me no issues so I've not actually revisted it.

@MattSidor
Copy link

MattSidor commented May 3, 2018

Thanks @thenathanjones, very helpful!

@dispix
Copy link

dispix commented Jun 20, 2018

I know create-react-app has a quite strict policy regarding the configurability of the tools it uses (in this case, webpack), but this issue can be quite challenging.

I am using styled-components and material-ui in a couple of projects, both personal and professional. Since they both inject style tags in the head element, the material-ui documentation indicates that it is possible to overcome css-priority issues by using a comment to define the insertion point of the jss-generated tags. This is where the issue with the current webpack configuration comes for me.

This is probably not such a uncommon use case and may suggest that the webpack configuration should not remove the comments when processing the html file ?

@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants