ant-design/c0ed2266-async.02346747.js
2025-06-10 09:02:15 +00:00

1 line
13 KiB
JavaScript

(("undefined"!=typeof globalThis?globalThis:self).makoChunk_antd=("undefined"!=typeof globalThis?globalThis:self).makoChunk_antd||[]).push([["c0ed2266"],{"44d30f5d":function(e,t,a){"use strict";a.d(t,"__esModule",{value:!0}),a.d(t,"texts",{enumerable:!0,get:function(){return n;}}),a("937572df");let n=[{value:"Next.js",paraId:0},{value:" is currently the most popular React server-side isomorphic framework in the world. This article will try to use ",paraId:0},{value:"antd",paraId:0},{value:" components in projects created by Next.js.",paraId:0},{value:"Before all start, you may need install ",paraId:1,tocIndex:0},{value:"yarn",paraId:1,tocIndex:0},{value:" or ",paraId:1,tocIndex:0},{value:"pnpm",paraId:1,tocIndex:0},{value:" or ",paraId:1,tocIndex:0},{value:"bun",paraId:1,tocIndex:0},{value:".",paraId:1,tocIndex:0},{value:"The tool will create and initialize environment and dependencies automatically, please try config your proxy setting, or use another npm registry if any network errors happen during it.",paraId:2},{value:"After the initialization is complete, we enter the project and start.",paraId:3},{value:"$ cd antd-demo\n$ npm run dev\n",paraId:4},{value:"Open the browser at ",paraId:5},{value:"http://localhost:3000/",paraId:5},{value:". if you see the NEXT logo, it is considered a success.",paraId:5},{value:"Now we install ",paraId:6,tocIndex:1},{value:"antd",paraId:6,tocIndex:1},{value:" from yarn or npm or pnpm or bun.",paraId:6,tocIndex:1},{value:"Modify ",paraId:7},{value:"src/app/page.tsx",paraId:7},{value:", import Button component from ",paraId:7},{value:"antd",paraId:7},{value:".",paraId:7},{value:"import React from 'react';\nimport { Button } from 'antd';\n\nconst Home = () => (\n <div className=\"App\">\n <Button type=\"primary\">Button</Button>\n </div>\n);\n\nexport default Home;\n",paraId:8},{value:"OK, you should now see a blue primary button displayed on the page. Next you can choose any components of ",paraId:9},{value:"antd",paraId:9},{value:" to develop your application. Visit other workflows of ",paraId:9},{value:"Next.js",paraId:9},{value:" at its ",paraId:9},{value:"User Guide",paraId:9},{value:".",paraId:9},{value:"You could find that components of antd do not have styles in the first screen. Next, you need to choose different SSR style processing methods according to the mode of Next.js.",paraId:10},{value:"Updated",paraId:11},{value:"If you are using the App Router in Next.js and using antd as your component library, to make the antd component library work better in your Next.js application and provide a better user experience, you can try using the following method to extract and inject antd's first-screen styles into HTML to avoid page flicker.",paraId:12,tocIndex:2},{value:"Install ",paraId:13,tocIndex:2},{value:"@ant-design/nextjs-registry",paraId:13,tocIndex:2},{value:"Use it in ",paraId:14},{value:"app/layout.tsx",paraId:14},{value:"import React from 'react';\nimport { AntdRegistry } from '@ant-design/nextjs-registry';\n\nconst RootLayout = ({ children }: React.PropsWithChildren) => (\n <html lang=\"en\">\n <body>\n <AntdRegistry>{children}</AntdRegistry>\n </body>\n </html>\n);\n\nexport default RootLayout;\n",paraId:15},{value:"Next.js App Router currently not support using sub-components via ",paraId:16},{value:".",paraId:16},{value:" like ",paraId:16},{value:"<Select.Option />",paraId:16},{value:" and ",paraId:16},{value:"<Typography.Text />",paraId:16},{value:". Importing them from path would solve this problem.",paraId:16},{value:"For more detailed information, please refer to ",paraId:17},{value:"with-nextjs-app-router-inline-style",paraId:17},{value:".",paraId:17},{value:"If you are using the Pages Router in Next.js and using antd as your component library, to make the antd component library work better in your Next.js application and provide a better user experience, you can try using the following method to extract and inject antd's first-screen styles into HTML to avoid page flicker.",paraId:18,tocIndex:3},{value:"Install ",paraId:19,tocIndex:3},{value:"@ant-design/cssinjs",paraId:19,tocIndex:3},{value:"Notes for developers",paraId:20,tocIndex:3},{value:"Please note that when you install ",paraId:21,tocIndex:3},{value:"@ant-design/cssinjs",paraId:21,tocIndex:3},{value:", you must ensure that the version is consistent with the version of ",paraId:21,tocIndex:3},{value:"@ant-design/cssinjs",paraId:21,tocIndex:3},{value:" in local ",paraId:21,tocIndex:3},{value:"node_modules",paraId:21,tocIndex:3},{value:" of ",paraId:21,tocIndex:3},{value:"antd",paraId:21,tocIndex:3},{value:", otherwise, multiple React instances will appear, resulting in ctx being unable to be read correctly. (Tips: you can use ",paraId:21,tocIndex:3},{value:"npm ls @ant-design/cssinjs",paraId:21,tocIndex:3},{value:" command to view the local version)",paraId:21,tocIndex:3},{value:"Rewrite ",paraId:22},{value:"pages/_document.tsx",paraId:22},{value:"import React from 'react';\nimport { createCache, extractStyle, StyleProvider } from '@ant-design/cssinjs';\nimport Document, { Head, Html, Main, NextScript } from 'next/document';\nimport type { DocumentContext } from 'next/document';\n\nconst MyDocument = () => (\n <Html lang=\"en\">\n <Head />\n <body>\n <Main />\n <NextScript />\n </body>\n </Html>\n);\n\nMyDocument.getInitialProps = async (ctx: DocumentContext) => {\n const cache = createCache();\n const originalRenderPage = ctx.renderPage;\n ctx.renderPage = () =>\n originalRenderPage({\n enhanceApp: (App) => (props) => (\n <StyleProvider cache={cache}>\n <App {...props} />\n </StyleProvider>\n ),\n });\n\n const initialProps = await Document.getInitialProps(ctx);\n const style = extractStyle(cache, true);\n return {\n ...initialProps,\n styles: (\n <>\n {initialProps.styles}\n <style dangerouslySetInnerHTML={{ __html: style }} />\n </>\n ),\n };\n};\n\nexport default MyDocument;\n",paraId:23},{value:"Supports custom themes",paraId:24},{value:"// theme/themeConfig.ts\nimport type { ThemeConfig } from 'antd';\n\nconst theme: ThemeConfig = {\n token: {\n fontSize: 16,\n colorPrimary: '#52c41a',\n },\n};\n\nexport default theme;\n",paraId:25},{value:"Rewrite ",paraId:26},{value:"pages/_app.tsx",paraId:26},{value:"import React from 'react';\nimport { ConfigProvider } from 'antd';\nimport type { AppProps } from 'next/app';\n\nimport theme from './theme/themeConfig';\n\nconst App = ({ Component, pageProps }: AppProps) => (\n <ConfigProvider theme={theme}>\n <Component {...pageProps} />\n </ConfigProvider>\n);\n\nexport default App;\n",paraId:27},{value:"Use antd in page component",paraId:28},{value:"import React from 'react';\nimport { Button } from 'antd';\n\nconst Home = () => (\n <div className=\"App\">\n <Button type=\"primary\">Button</Button>\n </div>\n);\n\nexport default Home;\n",paraId:29},{value:"For more detailed information, please refer to ",paraId:30},{value:"with-nextjs-inline-style",paraId:30},{value:".",paraId:30}];},c0ed2266:function(e,t,a){"use strict";a.d(t,"__esModule",{value:!0}),a.d(t,"default",{enumerable:!0,get:function(){return h;}});var n=a("777fffbe"),s=a("f19d2b93"),r=n._(a("e8387770")),l=n._(a("769c016e")),d=n._(a("b622e337")),o=n._(a("5437c7d5")),i=n._(a("97c488ea")),u=n._(a("c96b0d01")),p=a("5b220c3d"),c=a("9c86e52a"),x=a("44d30f5d"),h=function(){return(0,s.jsx)(c.DumiPage,{children:(0,s.jsx)(p.Suspense,{fallback:(0,s.jsx)(u.default,{}),children:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"markdown",children:[(0,s.jsxs)("p",{children:[(0,s.jsx)(i.default,{href:"https://nextjs.org/",sourceType:"a",children:x.texts[0].value}),x.texts[1].value,(0,s.jsx)("code",{children:x.texts[2].value}),x.texts[3].value]}),(0,s.jsxs)("h2",{id:"install-and-initialization",children:[(0,s.jsx)(i.default,{"aria-hidden":"true",tabIndex:"-1",href:"#install-and-initialization",sourceType:"a",children:(0,s.jsx)("span",{className:"icon icon-link"})}),"Install and Initialization"]}),(0,s.jsxs)("p",{children:[x.texts[4].value,(0,s.jsx)(i.default,{href:"https://github.com/yarnpkg/yarn/",sourceType:"a",children:x.texts[5].value}),x.texts[6].value,(0,s.jsx)(i.default,{href:"https://pnpm.io/",sourceType:"a",children:x.texts[7].value}),x.texts[8].value,(0,s.jsx)(i.default,{href:"https://bun.sh/",sourceType:"a",children:x.texts[9].value}),x.texts[10].value]})]}),(0,s.jsx)(o.default,{npm:"$ npx create-next-app antd-demo",yarn:"$ yarn create next-app antd-demo",pnpm:"$ pnpm create next-app antd-demo",bun:"$ bun create next-app antd-demo"}),(0,s.jsxs)("div",{className:"markdown",children:[(0,s.jsx)("p",{children:x.texts[11].value}),(0,s.jsx)("p",{children:x.texts[12].value}),(0,s.jsx)(d.default,{lang:"bash",children:x.texts[13].value}),(0,s.jsxs)("p",{children:[x.texts[14].value,(0,s.jsx)(i.default,{href:"http://localhost:3000/",sourceType:"a",children:x.texts[15].value}),x.texts[16].value]}),(0,s.jsxs)("h2",{id:"import-antd",children:[(0,s.jsx)(i.default,{"aria-hidden":"true",tabIndex:"-1",href:"#import-antd",sourceType:"a",children:(0,s.jsx)("span",{className:"icon icon-link"})}),"Import antd"]}),(0,s.jsxs)("p",{children:[x.texts[17].value,(0,s.jsx)("code",{children:x.texts[18].value}),x.texts[19].value]})]}),(0,s.jsx)(o.default,{npm:"$ npm install antd --save",yarn:"$ yarn add antd",pnpm:"$ pnpm install antd --save",bun:"$ bun add antd"}),(0,s.jsxs)("div",{className:"markdown",children:[(0,s.jsxs)("p",{children:[x.texts[20].value,(0,s.jsx)("code",{children:x.texts[21].value}),x.texts[22].value,(0,s.jsx)("code",{children:x.texts[23].value}),x.texts[24].value]}),(0,s.jsx)(d.default,{lang:"tsx",children:x.texts[25].value}),(0,s.jsxs)("p",{children:[x.texts[26].value,(0,s.jsx)("code",{children:x.texts[27].value}),x.texts[28].value,(0,s.jsx)("code",{children:x.texts[29].value}),x.texts[30].value,(0,s.jsx)(i.default,{href:"https://nextjs.org/",sourceType:"a",children:x.texts[31].value}),x.texts[32].value]}),(0,s.jsx)("p",{children:x.texts[33].value}),(0,s.jsxs)("h2",{id:"using-app-router",children:[(0,s.jsx)(i.default,{"aria-hidden":"true",tabIndex:"-1",href:"#using-app-router",sourceType:"a",children:(0,s.jsx)("span",{className:"icon icon-link"})}),"Using App Router ",(0,s.jsx)(r.default,{children:x.texts[34].value})]}),(0,s.jsx)("p",{children:x.texts[35].value}),(0,s.jsx)("ol",{children:(0,s.jsxs)("li",{children:[x.texts[36].value,(0,s.jsx)("code",{children:x.texts[37].value})]})})]}),(0,s.jsx)(o.default,{npm:"$ npm install @ant-design/nextjs-registry --save",yarn:"$ yarn add @ant-design/nextjs-registry",pnpm:"$ pnpm install @ant-design/nextjs-registry --save",bun:"$ bun add @ant-design/nextjs-registry"}),(0,s.jsxs)("div",{className:"markdown",children:[(0,s.jsx)("ol",{start:"2",children:(0,s.jsxs)("li",{children:[x.texts[38].value,(0,s.jsx)("code",{children:x.texts[39].value})]})}),(0,s.jsx)(d.default,{lang:"tsx",children:x.texts[40].value})]}),(0,s.jsx)(l.default,{type:"warning",children:(0,s.jsxs)("p",{children:[x.texts[41].value,(0,s.jsx)("code",{children:x.texts[42].value}),x.texts[43].value,(0,s.jsx)("code",{children:x.texts[44].value}),x.texts[45].value,(0,s.jsx)("code",{children:x.texts[46].value}),x.texts[47].value]})}),(0,s.jsxs)("div",{className:"markdown",children:[(0,s.jsxs)("p",{children:[x.texts[48].value,(0,s.jsx)(i.default,{href:"https://github.com/ant-design/ant-design-examples/tree/main/examples/with-nextjs-app-router-inline-style",sourceType:"a",children:x.texts[49].value}),x.texts[50].value]}),(0,s.jsxs)("h2",{id:"using-pages-router",children:[(0,s.jsx)(i.default,{"aria-hidden":"true",tabIndex:"-1",href:"#using-pages-router",sourceType:"a",children:(0,s.jsx)("span",{className:"icon icon-link"})}),"Using Pages Router"]}),(0,s.jsx)("p",{children:x.texts[51].value}),(0,s.jsx)("ol",{children:(0,s.jsxs)("li",{children:[x.texts[52].value,(0,s.jsx)("code",{children:x.texts[53].value})]})}),(0,s.jsxs)("blockquote",{children:[(0,s.jsx)("p",{children:x.texts[54].value}),(0,s.jsxs)("p",{children:[x.texts[55].value,(0,s.jsx)("code",{children:x.texts[56].value}),x.texts[57].value,(0,s.jsx)("code",{children:x.texts[58].value}),x.texts[59].value,(0,s.jsx)("code",{children:x.texts[60].value}),x.texts[61].value,(0,s.jsx)("code",{children:x.texts[62].value}),x.texts[63].value,(0,s.jsx)("code",{children:x.texts[64].value}),x.texts[65].value]}),(0,s.jsx)("img",{width:"514",alt:"image",src:"https://github.com/ant-design/ant-design/assets/49217418/aad6e9e2-62cc-4c89-a0b6-38c592e3c648"})]})]}),(0,s.jsx)(o.default,{npm:"$ npm install @ant-design/cssinjs --save",yarn:"$ yarn add @ant-design/cssinjs",pnpm:"$ pnpm install @ant-design/cssinjs --save",bun:"$ bun add @ant-design/cssinjs"}),(0,s.jsxs)("div",{className:"markdown",children:[(0,s.jsx)("ol",{start:"2",children:(0,s.jsxs)("li",{children:[x.texts[66].value,(0,s.jsx)("code",{children:x.texts[67].value})]})}),(0,s.jsx)(d.default,{lang:"tsx",children:x.texts[68].value}),(0,s.jsx)("ol",{start:"3",children:(0,s.jsx)("li",{children:x.texts[69].value})}),(0,s.jsx)(d.default,{lang:"ts",children:x.texts[70].value}),(0,s.jsx)("ol",{start:"4",children:(0,s.jsxs)("li",{children:[x.texts[71].value,(0,s.jsx)("code",{children:x.texts[72].value})]})}),(0,s.jsx)(d.default,{lang:"tsx",children:x.texts[73].value}),(0,s.jsx)("ol",{start:"5",children:(0,s.jsx)("li",{children:x.texts[74].value})}),(0,s.jsx)(d.default,{lang:"tsx",children:x.texts[75].value}),(0,s.jsxs)("p",{children:[x.texts[76].value,(0,s.jsx)(i.default,{href:"https://github.com/ant-design/ant-design-examples/tree/main/examples/with-nextjs-inline-style",sourceType:"a",children:x.texts[77].value}),x.texts[78].value]})]})]})})});};}}]);