【问题标题】:Tailwind CSS with Next.js not applicable带有 Next.js 的 Tailwind CSS 不适用
【发布时间】:2021-04-05 18:12:08
【问题描述】:

将 Tailwind CSS 引入 Next.js 环境。
我想申请color.lime,但出现以下错误。

./node_modules/tailwindcss/tailwind.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-5-1!./node_modules/next/dist/compiled/postcss-loader/cjs.js??ref--5-oneOf-5-2!./node_modules/tailwindcss/tailwind.css)
ReferenceError: color is not defined

tailwind.config.js

const colors = require(`tailwindcss/colors`);
module.exports = {
  purge: ["./src/**/*.{js,ts,jsx,tsx}"],
  darkMode: false, // 'media' or 'class'
  theme: { extend: { colors: { lime: color.lime } } },
  variants: { extend: {} },
  plugins: [],
};

__app.tsx

import "tailwindcss/tailwind.css";
import type { AppProps } from "next/app";
import Head from "next/head";

const App = (props: AppProps) => {
  return (
    <>
      <Head>
        <title>nexst</title>
      </Head>
      <props.Component {...props.pageProps} />
    </>
  );
};

// eslint-disable-next-line import/no-default-export
export default App;

【问题讨论】:

  • 你试过将colors: { lime: color.lime }移到extend: { }之外吗?

标签: next.js tailwind-css


【解决方案1】:

您的tailwind.config.js 中有错字,您应该使用colors.lime 而不是color.lime 访问颜色。

const colors = require(`tailwindcss/colors`);
module.exports = {
    purge: ["./src/**/*.{js,ts,jsx,tsx}"],
    darkMode: false, // 'media' or 'class'
    theme: { extend: { colors: { lime: colors.lime } } }, // here use `colors`
    variants: { extend: {} },
    plugins: [],
};

【讨论】:

    猜你喜欢
    • 2020-02-22
    • 2021-07-03
    • 2021-08-07
    • 2021-08-23
    • 2021-08-08
    • 1970-01-01
    • 2021-09-04
    • 1970-01-01
    • 2020-10-25
    相关资源
    最近更新 更多