9

由于某种原因,tailwind在 next.js 中没有正确呈现。

我想知道我的设置是否有问题?

样式文件夹 - tailwind.css

@尾风基地;

/* Write your own custom base styles here */

/* Start purging... */
@tailwind components;
/* Stop purging. */

/* Write you own custom component styles here */
.btn-blue {
  @apply bg-blue-500 text-white font-bold py-2 px-4 rounded;
}

/* Start purging... */
@tailwind utilities;
/* Stop purging. */

/* Your own custom utilities */

……

_app.js

import React from "react";
// import "styles/global.scss";


import 'styles/tailwind.css'


import NavbarCustom from "components/Layout/NavbarCustom";
import Footer from "components/Layout/Footer";
import "util/analytics.js";
import { ProvideAuth } from "util/auth.js";

function MyApp({ Component, pageProps }) {
  return (
    <ProvideAuth>
      <>
        <NavbarCustom
          bg="white"
          variant="light"
          expand="md"
          logo="icons/Logo_512px.png"
        />

        <Component {...pageProps} />

我究竟做错了什么?很困惑,通常这种设置很好。

这是网站顺便说一句 - https://mmap-1xr646x4a.vercel.app/

使用下面的信息,进行了更改,但奇怪的是仍然存在相同的问题。

https://mmap-hewlbern.moodmap.vercel.app/是站点示例。

tailwind.config.js

module.exports = {
  future: {
    removeDeprecatedGapUtilities: true,
  },
  purge: ['./components/**/*.{js,ts,jsx,tsx}', './pages/**/*.{js,ts,jsx,tsx}'],
  theme: {
    extend: {
      colors: {
        'accent-1': '#333',
      },
    },
  },
  variants: {},
  plugins: [],
}

postcss.config.js

module.exports = {
    plugins: [
      'tailwindcss',
      'postcss-flexbugs-fixes',
      [
        'postcss-preset-env',
        {
          autoprefixer: {
            flexbox: 'no-2009',
          },
          stage: 3,
          features: {
            'custom-properties': false,
          },
        },
      ],
    ],
  }

{
  "name": "MoodMap",
  "version": "0.1.0",
  "private": true,
  "keywords": [
    "MoodMap"
  ],
  "dependencies": {
    "@analytics/google-analytics": "0.2.2",
    "@stripe/stripe-js": "^1.5.0",
    "analytics": "0.3.1",
    "fake-auth": "0.1.7",
    "mailchimp-api-v3": "1.13.1",
    "next": "9.5.3",
    "query-string": "6.9.0",
    "raw-body": "^2.4.1",
    "rc-year-calendar": "^1.0.2",
    "react": "16.12.0",
    "react-dom": "16.12.0",
    "react-hook-form": "4.10.1",
    "react-query": "2.12.1",
    "react-transition-group": "^4.4.1",
    "stripe": "^8.52.0"
  },
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "stripe-webhook": "stripe listen --forward-to localhost:3000/api/stripe-webhook"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "postcss-flexbugs-fixes": "^4.2.1",
    "postcss-preset-env": "^6.7.0",
    "stylelint": "^13.7.1",
    "stylelint-config-standard": "^20.0.0",
    "tailwindcss": "^1.8.9"
  }
}

谢谢!

4

7 回答 7

16

我的项目存在同样的问题,但我尝试更改globals.css如下:

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900');

@tailwind base;
@tailwind components;
@tailwind utilities;

@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import './base.css';
@import 'tailwindcss/utilities';
于 2021-05-17T10:13:09.953 回答
3

我觉得你的设置太大了。现在你可以用更简单的东西来实现这一点。

首先,我认为不再需要将 CSS 加载到 nextjs 中,并且原生支持模块。(所以你可以用CSS的东西删除这个)

其次,如果您使用较新的版本,顺风不再需要如此复杂的设置。

所以你需要安装 postcss-preset-env,但它现在确实不需要大配置。

查看此示例https://github.com/vercel/next.js/tree/canary/examples/with-tailwindcss

于 2020-09-24T12:57:40.973 回答
3

我的一个项目安装了这些软件包版本

"next": "11.1.0",
"autoprefixer": "^10.3.3",
"postcss": "^8.3.6",
"tailwindcss": "^2.2.8"

此设置tailwind.config.js有效:

module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
};

最近我用这些包开始了一个新项目:

"next": "12.0.8",
"autoprefixer": "^10.4.2",
"postcss": "^8.4.5",
"tailwindcss": "^3.0.15"

以前的配置设置不起作用。所以我将其更改为:

module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};
于 2022-01-21T01:35:25.117 回答
2

对我来说,解决方案是./src/...tailwind.config.js. 官方 Next.JS + Tailwindcss 示例不支持 src 文件夹。

于 2022-01-10T19:21:45.353 回答
1

我在某些文件中遇到了同样的问题。

在删除所有内联顺风类并将它们放入 CSS 文件@apply之后效果很好。

于 2021-10-11T01:05:19.433 回答
0
postcss.config.js

    module.exports = {
      plugins: {
        tailwindcss: {},
        autoprefixer: {},
      },
    }
tailwind.config.js

    module.exports = {
      mode: 'jit',
      content: [
        "./**/*.{js,ts,jsx,tsx}",
      ],
      theme: {
        extend: {},
      },
      plugins: [],
    }
全局.css

    @tailwind base;
    @tailwind components;
    @tailwind utilities;
于 2022-02-09T11:32:03.513 回答
0

我也遇到过这种情况,但我的解决方案是编辑 tailwind.connfig.js

取决于版本

对于版本 2

module.exports = {
 purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
 theme: {
   extend: {},
 },
 variants: {
   extend: {},
 },
 plugins: [],
}

对于版本 3

module.exports = {
  content: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}
于 2022-02-20T08:12:26.453 回答