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

html comments not removed #360

Closed
enricogallesio opened this issue May 16, 2024 · 7 comments
Closed

html comments not removed #360

enricogallesio opened this issue May 16, 2024 · 7 comments
Assignees

Comments

@enricogallesio
Copy link

Hello!
I'm not sure if this the expected behavior but comments in html are not removed in my build.
I even tried

html: {
removeComments: true,
},

in the astro config file but comments are still there.

Any clue why this happens?
thanks!

@NikolaRHristov
Copy link
Member

Hi @enricogallesio

html: {
removeComments: true,
},

is invalid option syntax. You should do:

(await import("@playform/compress")).default({
	HTML: {
		"html-minifier-terser": {
			removeComments: true
		}
	}
}),

@enricogallesio
Copy link
Author

Hi @NikolaRHristov, thanks for your help.
I tried with this syntax but I'm still getting html comments in my build.

I'm not sure what is wrong. I'm also using icon, tailwind and sitemap integrations.
Not sure it this is relevant, but I've also disabled images compression since it is incredibly slow, and I'm not sure if that's worth since most of my images are optimized anyway.

This is my astro.config.mjs

import {defineConfig} from "astro/config";
import sitemap from "@astrojs/sitemap";
import tailwind from "@astrojs/tailwind";
import icon from "astro-icon";

import playformCompress from "@playform/compress";

export default defineConfig({
      site: "https://www.MYWEBSITE.org"

      integrations: [
            sitemap(),
            tailwind(),
            icon(),
            (await import("@playform/compress")).default({
                  Image: false,
                  HTML: {
                        "html-minifier-terser": {
                              removeComments: true,
                        },
                  },
            }),
      ],
      image: {
            remotePatterns: [
                  {
                        hostname: "192.168.6.11",
                        port: "8055",
                  },
            ],
      },
      prefetch: {
            prefetchAll: true,
      },
});

any idea? thanks!

@NikolaRHristov
Copy link
Member

We've also added new ignoreCustomComments in the new astro-compress v2.2.23 and @playform/compress v0.0.4

ignoreCustomComments: [
/^\s*#/,
/.*$.*/,
/^\s*\[/,
/^\s*\]/,
/^\s*!/,
/^\s*\//,
],

	ignoreCustomComments: [
		/^\s*#/,
		/.*$.*/,
		/^\s*\[/,
		/^\s*\]/,
		/^\s*!/,
		/^\s*\//,
	],

which might interfere with this. Can you also set ignoreCustomComments to be an empty array ? Like so:

import {defineConfig} from "astro/config";
import sitemap from "@astrojs/sitemap";
import tailwind from "@astrojs/tailwind";
import icon from "astro-icon";

import playformCompress from "@playform/compress";

export default defineConfig({
      site: "https://www.MYWEBSITE.org"

      integrations: [
            sitemap(),
            tailwind(),
            icon(),
            (await import("@playform/compress")).default({
                  Image: false,
                  HTML: {
                        "html-minifier-terser": {
                              removeComments: true,
                              ignoreCustomComments: [],
                        },
                  },
            }),
      ],
      image: {
            remotePatterns: [
                  {
                        hostname: "192.168.6.11",
                        port: "8055",
                  },
            ],
      },
      prefetch: {
            prefetchAll: true,
      },
});

@enricogallesio
Copy link
Author

HTML: {
                        "html-minifier-terser": {
                              removeComments: true,
                              ignoreCustomComments: [],
                        },
                  },

This seems to have solved the issue! 👍
Thank you very much @NikolaRHristov !

@NikolaRHristov
Copy link
Member

NikolaRHristov commented May 19, 2024

Can I just check, sorry to bother. What were the comments that were not getting removed ? Can you paste an example ?

@enricogallesio
Copy link
Author

enricogallesio commented May 19, 2024

I'm not sure but it looks like all of them were not getting removed. Those are plain simple

<!-- some text -->

and

<!-- ---- SECTION x ---- -->

I guess there must be something messy in the code that interferes with that, possibly some non properly closed comment field?
Let me know if I can somehow help

@Boston343
Copy link

We've also added new ignoreCustomComments in the new astro-compress v2.2.23 and @playform/compress v0.0.4

ignoreCustomComments: [
/^\s*#/,
/.*$.*/,
/^\s*\[/,
/^\s*\]/,
/^\s*!/,
/^\s*\//,
],

	ignoreCustomComments: [
		/^\s*#/,
		/.*$.*/,
		/^\s*\[/,
		/^\s*\]/,
		/^\s*!/,
		/^\s*\//,
	],

which might interfere with this. Can you also set ignoreCustomComments to be an empty array ? Like so:

import {defineConfig} from "astro/config";
import sitemap from "@astrojs/sitemap";
import tailwind from "@astrojs/tailwind";
import icon from "astro-icon";

import playformCompress from "@playform/compress";

export default defineConfig({
      site: "https://www.MYWEBSITE.org"

      integrations: [
            sitemap(),
            tailwind(),
            icon(),
            (await import("@playform/compress")).default({
                  Image: false,
                  HTML: {
                        "html-minifier-terser": {
                              removeComments: true,
                              ignoreCustomComments: [],
                        },
                  },
            }),
      ],
      image: {
            remotePatterns: [
                  {
                        hostname: "192.168.6.11",
                        port: "8055",
                  },
            ],
      },
      prefetch: {
            prefetchAll: true,
      },
});

FWIW, I was having the same issue and adding this section

HTML: {
      "html-minifier-terser": {
            removeComments: true,
            ignoreCustomComments: [],
      },
},

also solved it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants