reactjs - 顺风 CSS 的某些部分无法在生产中运行
问题描述
我为我的下一个 JS 应用程序构建了一个静态网站,该应用程序使用 tailwind CSS 进行样式设置。我将静态用作 CDN。开发服务器(本地主机)中的网站运行良好。但是,在生产中,样式的某些部分似乎被破坏了(准确地说是页眉、页脚以及在暗/亮模式之间切换)。附上截图供参考。
本地服务器:
当我检查本地和生产环境中的相应元素时,HTML 结构和类名似乎没有区别,但是当我将鼠标悬停在生产中损坏的元素(本例中为导航项)上时,相应的元素没有突出显示。到目前为止,这是我能够找到的。以下是一些配置文件
next.config.js
:
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
reactStrictMode: true,
images: {
// domains: ['raw.githubusercontent.com','ibb.co'],
domains: ['raw.githubusercontent.com'],
loader:'imgix',
path:''
},
assetPrefix: isProd ? 'CDN_LINK_HERE' : '',
}
tailwind.config.css
:
module.exports = {
purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
darkMode: 'class', // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
我该如何解决这个问题?谢谢。
解决方案
确保将需要应用 CSS 的完整路径列表添加到tailwind.config.css
.
module.exports = {
// ▼ here you need to add all paths according to your needs
purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}', './your-other-component-folder/**/*.{js,ts,jsx,tsx}'],
darkMode: 'class', // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
推荐阅读
- serialization - 从 protobuf 消息中删除现有字段会导致问题吗?
- tensorflow - 如何将 y_true 的值数组映射到单个值,以便与 Tensorflow 损失函数中的 y_pred 进行比较(Tensorflow/Tensorflow Quantum)
- java - 如何在 OpenAPI 3.0 中定义字节数组
- apache-spark-sql - Spark-sql 数据砖中的变量动态分配值
- excel - 通过 Excel VBA 的 NumberFormat
- reactjs - 在单独的文件中反应放置标题
- spring - 有没有办法在不从数据库中检索对象的情况下将对象添加到 spring 的持久性上下文中?
- java - 使用 navigationComponent 保留 BottomNavigationView 中哪个片段处于活动状态
- octave - 'endif' 命令与 octave 中的 'endfor' 问题匹配
- php - 除非我检查元素,否则不会设置 Cookie