我项目中的所有样式都是在 css 模块内定义的,直到最近我才注意到,在 Nextjs 生成的生产版本中,其中一些样式被其他样式覆盖(这只有在它们定义在同一模块上时才有意义,但事实并非如此)。这在生产中破坏了我的应用程序,但在开发中一切似乎都运行良好。
这是一个例子:
///mobile.module.css
.expandIcon {
width: 12px;
}
///mobile.tsx
import React from "react";
import styles from "./mobile.module.css";
import { NextPage } from "next";
import OpenInFullRoundedIcon from "@mui/icons-material/OpenInFullRounded";
const mobile: NextPage = () => {
return <OpenInFullRoundedIcon className={styles.expandIcon} />
};
export default mobile;
Run Code Online (Sandbox Code Playgroud)
以下是该类在开发时的加载方式:
下面是它在 prod 上被重写的方式:
更糟糕的是,我的项目中甚至没有定义覆盖我的类。我对 NextJs 有点陌生,所以我将不胜感激对此问题的任何见解。