赞
踩
上一篇介绍了nextjs 的配置,这章主要是引入tailwindcss
和antd
.
https://www.nextjs.cn/docs/advanced-features/customizing-postcss-config
next 提供了postcss 开箱即用
https://www.tailwindcss.cn/docs/guides/nextjs
npm install -D tailwindcss@latest postcss@latest autoprefixer@latest
npx tailwindcss init -p
tailwind.config.js
和 postcss.config.js
purge: ["./pages/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
styles/tailwind.css
@tailwind base;
@tailwind components;
@tailwind utilities;
pages/_app.tsx
引入styles/tailwind.css
:import "../styles/globals.css";
import "../styles/tailwind./* */css";
import type { AppProps } from "next/app";
function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
}
export default MyApp;
pages/index.tsx
:import type { NextPage } from "next"; import Head from "next/head"; const Home: NextPage = () => { return ( <div className=""> <Head> <title>Create Next App</title> <meta name="description" content="Generated by create next app" /> <link rel="icon" href="/favicon.ico" /> </Head> <main> <div className="flex justify-center text-[red]"> tailwindcss</div> </main> </div> ); }; export default Home;
ok! 大功告成。
官方:
https://www.nextjs.cn/docs/basic-features/built-in-css-support
npm install sass
next.config.js
中sassOptions
(略)pages/helloWorld/index.module.scss
.helloWorld {
.scsstest {
color: red;
}
}
pages/helloWorld/index.tsx
import styles from "./index.module.scss";
function About() {
return (
<div className={styles.helloWorld}>
<div className={styles.scsstest}>helloWord</div>
</div>
);
}
export default About;
yarn add next-plugin-antd-less
yarn add --dev babel-plugin-import
module.exports = {
presets: [['next/babel']],
plugins: [['import', { libraryName: 'antd', style: true }]],
};
next.config.js
:/** @type {import('next').NextConfig} */
const withAntdLess = require("next-plugin-antd-less");
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
};
module.exports = withAntdLess(nextConfig);
pages/index.tsx
:import type { NextPage } from "next"; import Head from "next/head"; import { Button } from "antd"; const Home: NextPage = () => { return ( <div className=""> <Head> <title>Create Next App</title> <meta name="description" content="Generated by create next app" /> <link rel="icon" href="/favicon.ico" /> </Head> <main> <div className="flex justify-center text-[red]"> tailwindcss <Button type="primary">test Antd</Button> </div> </main> </div> ); };
引入了这三个开发配置。
下一篇开发博客:)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。