Unverified Commit 2dcd4e95 authored by mit123suki's avatar mit123suki Committed by GitHub

example: antd-4 with built-in css support (#11837)

parent e19023d6
{
"presets": ["next/babel"],
"plugins": [
[
"import",
{
"libraryName": "antd",
"libraryDirectory": "es",
"style": "index.css"
}
],
[
"import",
{
"libraryName": "@ant-design/icons",
"libraryDirectory": "es/icons",
"camel2DashComponentName": false
},
"@ant-design/icons"
]
]
}
const compose = plugins => ({
webpack(config, options) {
return plugins.reduce((config, plugin) => {
if (plugin instanceof Array) {
const [_plugin, ...args] = plugin
plugin = _plugin(...args)
}
if (plugin instanceof Function) {
plugin = plugin()
}
if (plugin && plugin.webpack instanceof Function) {
return plugin.webpack(config, options)
}
return config
}, config)
},
webpackDevMiddleware(config) {
return plugins.reduce((config, plugin) => {
if (plugin instanceof Array) {
const [_plugin, ...args] = plugin
plugin = _plugin(...args)
}
if (plugin instanceof Function) {
plugin = plugin()
}
if (plugin && plugin.webpackDevMiddleware instanceof Function) {
return plugin.webpackDevMiddleware(config)
}
return config
}, config)
},
})
const withBundleAnalyzer = require('@next/bundle-analyzer')
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin')
module.exports = compose([
{
webpack(config, { buildId, dev, isServer, defaultLoaders, webpack }) {
config.plugins.push(new AntdDayjsWebpackPlugin())
return config
},
},
[
withBundleAnalyzer,
{
enabled: process.env.ANALYZE === 'true',
},
],
])
...@@ -2,16 +2,24 @@ ...@@ -2,16 +2,24 @@
"name": "with-ant-design", "name": "with-ant-design",
"version": "1.0.0", "version": "1.0.0",
"scripts": { "scripts": {
"dev": "next", "dev": "cross-env NODE_OPTIONS=\"-r esm\" next",
"build": "next build", "build": "cross-env NODE_OPTIONS=\"-r esm\" next build",
"analyze": "cross-env-shell NODE_OPTIONS=\"-r esm\" ANALYZE=true next build",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"@zeit/next-css": "^1.0.1", "@ant-design/icons": "^4.0.6",
"antd": "^4.0.1", "@next/bundle-analyzer": "^9.1.4",
"next": "latest", "antd": "4.1.2",
"react": "^16.7.0", "antd-dayjs-webpack-plugin": "1.0.0",
"react-dom": "^16.7.0" "babel-plugin-import": "1.13.0",
"cross-env": "^7.0.2",
"dayjs": "1.8.24",
"esm": "^3.2.25",
"next": "9.3.4",
"postcss-preset-env": "^6.7.0",
"react": "16.13.1",
"react-dom": "16.13.1"
}, },
"license": "ISC" "license": "ISC"
} }
import React from 'react'
import 'antd/dist/antd.css' import 'antd/dist/antd.css'
import '../styles/vars.css'
import '../styles/global.css'
export default function MyApp({ Component, pageProps }) { export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} /> return <Component {...pageProps} />
......
import React from 'react'
import { import {
Form, Form,
Select, Select,
...@@ -8,11 +9,29 @@ import { ...@@ -8,11 +9,29 @@ import {
Button, Button,
} from 'antd' } from 'antd'
import { SmileFilled } from '@ant-design/icons'
import Link from 'next/link'
const FormItem = Form.Item const FormItem = Form.Item
const Option = Select.Option const Option = Select.Option
const content = {
marginTop: '100px',
}
export default () => ( export default () => (
<div style={{ marginTop: 100 }}> <div style={content}>
<div className="text-center mb-5">
<Link href="#">
<a className="logo mr-0">
<SmileFilled size={48} strokeWidth={1} />
</a>
</Link>
<p className="mb-0 mt-3 text-disabled">Welcome to the world !</p>
</div>
<div>
<Form layout="horizontal"> <Form layout="horizontal">
<FormItem <FormItem
label="Input Number" label="Input Number"
...@@ -27,18 +46,29 @@ export default () => ( ...@@ -27,18 +46,29 @@ export default () => (
defaultValue={3} defaultValue={3}
name="inputNumber" name="inputNumber"
/> />
<a href="#">Link</a>
</FormItem> </FormItem>
<FormItem label="Switch" labelCol={{ span: 8 }} wrapperCol={{ span: 8 }}> <FormItem
label="Switch"
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<Switch defaultChecked name="switch" /> <Switch defaultChecked name="switch" />
</FormItem> </FormItem>
<FormItem label="Slider" labelCol={{ span: 8 }} wrapperCol={{ span: 8 }}> <FormItem
label="Slider"
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<Slider defaultValue={70} /> <Slider defaultValue={70} />
</FormItem> </FormItem>
<FormItem label="Select" labelCol={{ span: 8 }} wrapperCol={{ span: 8 }}> <FormItem
label="Select"
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<Select <Select
size="large" size="large"
defaultValue="lucy" defaultValue="lucy"
...@@ -71,4 +101,5 @@ export default () => ( ...@@ -71,4 +101,5 @@ export default () => (
</FormItem> </FormItem>
</Form> </Form>
</div> </div>
</div>
) )
*,
*:before,
*:after {
box-sizing: inherit;
}
html {
box-sizing: border-box;
font-size: 14px;
-ms-overflow-style: -ms-autohiding-scrollbar;
}
body {
background-color: var(--backgroundColor);
-ms-text-size-adjust: 100%;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
}
.text-left {
text-align: left !important;
}
.text-right {
text-align: right !important;
}
.text-center {
text-align: center !important;
}
.m-0 {
margin: 0 !important;
}
.mt-0,
.my-0 {
margin-top: 0 !important;
}
.mr-0,
.mx-0 {
margin-right: 0 !important;
}
.mb-0,
.my-0 {
margin-bottom: 0 !important;
}
.ml-0,
.mx-0 {
margin-left: 0 !important;
}
.m-1 {
margin: 0.25rem !important;
}
.mt-1,
.my-1 {
margin-top: 0.25rem !important;
}
.mr-1,
.mx-1 {
margin-right: 0.25rem !important;
}
.mb-1,
.my-1 {
margin-bottom: 0.25rem !important;
}
.ml-1,
.mx-1 {
margin-left: 0.25rem !important;
}
.m-2 {
margin: 0.5rem !important;
}
.mt-2,
.my-2 {
margin-top: 0.5rem !important;
}
.mr-2,
.mx-2 {
margin-right: 0.5rem !important;
}
.mb-2,
.my-2 {
margin-bottom: 0.5rem !important;
}
.ml-2,
.mx-2 {
margin-left: 0.5rem !important;
}
.m-3 {
margin: 1rem !important;
}
.mt-3,
.my-3 {
margin-top: 1rem !important;
}
.mr-3,
.mx-3 {
margin-right: 1rem !important;
}
.mb-3,
.my-3 {
margin-bottom: 1rem !important;
}
.ml-3,
.mx-3 {
margin-left: 1rem !important;
}
.m-4 {
margin: 1.5rem !important;
}
.mt-4,
.my-4 {
margin-top: 1.5rem !important;
}
.mr-4,
.mx-4 {
margin-right: 1.5rem !important;
}
.mb-4,
.my-4 {
margin-bottom: 1.5rem !important;
}
.ml-4,
.mx-4 {
margin-left: 1.5rem !important;
}
.m-5 {
margin: 3rem !important;
}
.mt-5,
.my-5 {
margin-top: 3rem !important;
}
.mr-5,
.mx-5 {
margin-right: 3rem !important;
}
.mb-5,
.my-5 {
margin-bottom: 3rem !important;
}
.ml-5,
.mx-5 {
margin-left: 3rem !important;
}
.logo {
display: flex;
align-items: center;
margin-right: 1rem;
font-size: 1.25rem;
white-space: nowrap;
color: var(--primaryColor);
justify-content: center;
}
.logo > svg {
fill: var(--primaryColor);
}
.text-disabled {
color: var(--textColorSecondary) !important;
}
:root {
--backgroundColor: #f7f7f7;
--primaryColor: #191a1b;
--textColorSecondary: rgba(0, 0, 0, 0.45);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment