Tailwind CSS with Next.js 不适用
Tailwind CSS with Next.js not applicable
将 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;
您的 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: [],
};
将 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;
您的 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: [],
};