我正在尝试使用 PurgeCSS 从我的 NextJS 项目中删除未使用的 css。然而,我很难将 PurgeCSS 最基本的集成到我的项目中来工作。
我正在使用此文档: https: //www.purgecss.com/guides/next。
我的 next.config 文件如下所示:
// next.config.js
const withCss = require('@zeit/next-css')
const withPurgeCss = require('next-purgecss')
module.exports = withCss(withPurgeCss())
Run Code Online (Sandbox Code Playgroud)
这是我的组件:
import React from 'react'
import App from 'next/app'
export default class MyApp extends App {
render() {
const { Component, pageProps } = this.props
return (
<>
<style jsx global>{`
.purgecss-test {
color: red;
}
`}</style>
<Component {...pageProps} />
</>
)
}
}
Run Code Online (Sandbox Code Playgroud)
当我在代码库中对“purgecss-test”进行全局搜索时,我只得到上面组件中的一个结果,因此我希望在构建过程中删除该样式。但是,当我的应用程序构建并导航到该页面并检查源代码时,我仍然可以在那里看到它:
<style amp-custom="">.purgecss-test{color:red;}
Run Code Online (Sandbox Code Playgroud) next.js ×1