0

I am using nextjs + reactjs .I want to remove all css comments present in my css file. For example, a created a simple project for next js. I am using next-purgecss to remove unwanted css but still, it is not removing comments why?

here is my code https://codesandbox.io/s/sharp-jennings-upb7y?file=/next.config.js:73-86 I added a comment in my css file

/*

heloo terr
 */
a {
  background-color: green;
}

It should be removed after using purgecss plugin.Is there any way to remove these comments

enter image description here

To run code create a new terminal and run npm run dev as it open at 3005 port

enter image description here

brc-dd
  • 10,788
  • 3
  • 47
  • 67
user5711656
  • 3,310
  • 4
  • 33
  • 70
  • I checked purgecss documentation but didn't find any info on how it can remove the comments. It just says "PurgeCSS is a tool to remove unused CSS." Maybe it just removes unused classes etc. but not comments – Ozgur Sar Nov 08 '20 at 08:34
  • Maybe answers on this question may help. Even though they are not using purgecss, someone suggested a different plugin for webpack. https://stackoverflow.com/questions/43360631/how-to-remove-all-comments-with-css-loader-with-webpack-2-in-string-mode – Ozgur Sar Nov 08 '20 at 08:36

1 Answers1

0

Next.js removes comments in CSS automatically. You don't need an extra configuration or CSS processing packages. Run the project in production mode using npm run build and npm start and comments would be removed from the build.

Generally, in development mode (next dev), the build is not optimized for production.

Nikolai Kiselev
  • 6,201
  • 2
  • 27
  • 37
  • I checked `npm run build` it not removed the comments – user5711656 Nov 08 '20 at 09:53
  • @user5711656, in your project you're overriding the built-in CSS and SASS loaders with _legacy_ packages `@zeit/next-css` and `@zeit/next-sass`. They are obsolete now and need to be removed. See steps [here](https://stackoverflow.com/questions/60941853/next-js-global-css-cannot-be-imported-from-files-other-than-your-custom-app/60944296#60944296) – Nikolai Kiselev Nov 08 '20 at 09:57
  • Thanks for answering than how to `add css` file and `remove unwanted css files` – user5711656 Nov 08 '20 at 10:01
  • Actually in my project I have few `scss` and `css` file .In my css file there so my `unused class` are there that why I use `purgecss` plugin .unused `css` is removed but there comments is not removed – user5711656 Nov 08 '20 at 10:03
  • see my example I am using both `scss` and `css` in `_app.js` import "./style.css"; import "../styles.css"; https://codesandbox.io/s/sharp-jennings-upb7y?file=/pages/_app.js:85-130 .In `css` file there are some unwanted `css` is present .I want `unused` css will be remove with `comments` .is it possible – user5711656 Nov 08 '20 at 10:06
  • is there any way to removed unused and comments – user5711656 Nov 08 '20 at 10:18