next.js - Tailwind CSS 在构建后未应用样式
问题描述
我已经使用 Tailwindcss 创建了 Next Js 应用程序,在开发环境中一切正常,但是当我使用 npm run build 命令时,我的 tailwind CSS 在代码中没有工作,但 CSS 没有应用
这是我的代码:
_app.js
import "tailwindcss/tailwind.css";
const MyApp = ({ Component, pageProps }) => {
return (
<>
<Component {...pageProps} />
</>
);
};
export default MyApp;
全局的.css
/* ./styles/globals.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
顺风配置.js
module.exports = {
mode: "jit",
purge: ["./pages/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
colors: {
primary: "#000000",
Secondary: "#FFFFFF",
},
zIndex: {
auto: "auto",
negative: "-1",
Secondary: "#FFFFFF",
},
},
},
variants: {
extend: {},
},
plugins: [],
};
解决方案
您需要安装postcss 和 autoprefixer。安装后,在您的根目录中创建一个postcss.config.js文件。
postcss.config.js
module.exports = {
plugins: {
autoprefixer: {},
tailwindcss: {},
},
};
推荐阅读
- java - IndexOutOfBoundsException setSpan (10 … 10) 结束超过长度 3
- python - 在django框架中将数据从python传递到html视图
- amazon-web-services - Nmap 找不到监听端口
- python - 按下时按钮不单击/调用功能
- php - 如何修复 PHP STORM 中关于 PHP 代码中的 SQL 故障的 PHP 消息?
- laravel - 用户数据未保存到 Laravel 6 中的数据库
- c# - EFCore 3.1 添加默认阴影属性并将它们用于软删除
- python - 我需要在 Python 中访问元组
- html - 打开模态覆盖时仍然可以看到一些元素
- android - 三星设备上缩放的画布 drawBitmap 上的模糊像素绘制