查看: 70|回覆: 0

next.js 集成css antd

[複製鏈接]

4

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2010-5-25
發表於 2020-1-15 15:55:00 | 顯示全部樓層 |閲讀模式

next使用 @zeit/next-css 支持import css

安装:npm install --save @zeit/next-css || yarn add @zeit/next-css
配置:
// next.config.js
// next支持import css const withCSS = require('@zeit/next-css') module.exports = withCSS({ /* config options here */ })

 

next集成antd

安装:yarn add antd  &&  yarn add babel-plugin-import --dev 

配置:

// .babelrc
// 重写扩展next的babel默认配置 { "presets": ["next/babel"], // antd babel-plugin-import 配置 style:true 优化打包 "plugins": [["import", { "libraryName": "antd"}]] // style:css 选项配置与webpackmincss有bug }

全局引入antd.css:

// pages/_app.js
// 重写覆盖next的app.js import App, { Container } from "next/app"; import Layout from "../components/Layout"; import {Provider} from 'react-redux' import withRedux from '../lib/with-redux' import "antd/dist/antd.min.css"; class MyApp extends App { render() { const { Component, pageProps, reduxStore } = this.props; return ( <Layout> <Provider store={reduxStore}> <Component {...pageProps} /> </Provider> </Layout> ); } } export default withRedux(MyApp)  

使用:

import { Button } from 'antd';

export default ({counter, user, add, rename}) => 
    <Button>CLICK</Button>

  

以上。 



来源:https://www.cnblogs.com/kongchuan/p/12197171.html
回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部