简体   繁体   English

如何将 PurgeCSS 与 Next.js 和 module.scss 文件一起使用?

[英]How do I use PurgeCSS with Next.js and module.scss files?

I've got component level.scss files (filename.module.scss) and I want to purge unused css from these files.我有组件 level.scss 文件 (filename.module.scss),我想从这些文件中清除未使用的 css。

Since the styling classnames get hashed.由于样式类名被散列。 I was wondering how I can get purgeCSS to work with a next.js app that uses module.scss files for most of the styling.我想知道如何让 purgeCSS 与 next.js 应用程序一起使用,该应用程序使用 module.scss 文件进行大部分样式设置。

https://github.com/FullHuman/purgecss/issues/163#issuecomment-526607181 this issue here goes over it but for a react application https://github.com/FullHuman/purgecss/issues/163#issuecomment-526607181这个问题在这里解决了它但是对于反应应用程序

You can use a dedicated NPM package next-purge-css-modules , made just for this purpose:您可以使用专门为此目的制作的专用 NPM package next-purge-css-modules

npm install next-purge-css-modules

and in your next.config.js , use:在你的next.config.js中,使用:

const withPurgeCSSModules = require('next-purge-css-modules');
const nextConfig = { ... };

module.exports = withPurgeCSSModules(nextConfig);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM