์ด ๊ฒฝ๊ณ ๋ ์จ๋ผ์ธ ํ๊ฒฝ์์ ์ฌํํ ์ ์์ผ๋ฏ๋ก ์ง์ ์ ์ถํฉ๋๋ค.
Next.js ํ๋ก์ ํธ์์ Ant Design์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. babel-plugin-import
๋ฅผ ์ฌ์ฉํ์ฌ ์์ฒญ ์ antd ๊ตฌ์ฑ ์์๋ฅผ ๋ก๋ํฉ๋๋ค. ์ฒซ ํ์ด์ง๋ฅผ ๋ณด์ฌ๋ ๊ด์ฐฎ์ง๋ง ๋ค๋ฅธ ํ์ด์ง๋ก ๋์ด๊ฐ๋ฉด ๋ค์๊ณผ ๊ฐ์ ๊ฒฝ๊ณ ๊ฐ ๋์ต๋๋ค.
chunk styles [mini-css-extract-plugin]
Conflicting order between:
* css ./node_modules/css-loader??ref--5-2!./node_modules/less-loader/dist/cjs.js??ref--5-3!./node_modules/antd/lib/button/style/index.less
* css ./node_modules/css-loader??ref--5-2!./node_modules/less-loader/dist/cjs.js??ref--5-3!./node_modules/antd/lib/dropdown/style/index.less
๊ทธ๋ฆฌ๊ณ ํ์ด์ง์ ์คํ์ผ์ด ์ฌ๋ฐ๋ฅด์ง ์์ ์๋ก ๊ณ ์นจ ํ ์ ์์ด ๋์์ต๋๋ค.
๋ํ ํ๋ก์ ํธ๋ฅผ ๋น๋ํ ๋ ๋ค์๊ณผ ๊ฐ์ ๊ฒฝ๊ณ ๋ฅผ ๋ฐ์์ต๋๋ค.
โ web git:(master) โ npm run build
> [email protected] build /Users/jagger/projects/jwpay/web
> next build
โ Client
Compiled successfully in 12.77s
โ Server
Compiled successfully in 8.64s
> Using external babel configuration
> Location: "/Users/jagger/projects/jwpay/web/.babelrc"
> Emitted warnings from webpack
Error: chunk commons [mini-css-extract-plugin]
Conflicting order between:
* css ./node_modules/css-loader??ref--5-1!./node_modules/less-loader/dist/cjs.js??ref--5-2!./node_modules/antd/lib/button/style/index.less
* css ./node_modules/css-loader??ref--5-1!./node_modules/less-loader/dist/cjs.js??ref--5-2!./node_modules/antd/lib/dropdown/style/index.less
at MiniCssExtractPlugin.renderContentAsset (/Users/jagger/projects/jwpay/web/node_modules/mini-css-extract-plugin/dist/index.js:342:37)
at Object.render (/Users/jagger/projects/jwpay/web/node_modules/mini-css-extract-plugin/dist/index.js:173:32)
at Compilation.createChunkAssets (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:2429:29)
at hooks.optimizeTree.callAsync.err (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:1299:10)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:9:1)
at AsyncSeriesHook.lazyCompileHook (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/Hook.js:154:20)
at Compilation.seal (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:1244:27)
at hooks.make.callAsync.err (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compiler.js:624:17)
at _err0 (eval at create (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:11:1)
at Promise.all.then (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/DynamicEntryPlugin.js:74:20)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
Error: chunk commons [mini-css-extract-plugin]
Conflicting order between:
* css ./node_modules/css-loader??ref--5-1!./node_modules/less-loader/dist/cjs.js??ref--5-2!./node_modules/antd/lib/dropdown/style/index.less
* css ./node_modules/css-loader??ref--5-1!./node_modules/less-loader/dist/cjs.js??ref--5-2!./node_modules/antd/lib/icon/style/index.less
at MiniCssExtractPlugin.renderContentAsset (/Users/jagger/projects/jwpay/web/node_modules/mini-css-extract-plugin/dist/index.js:342:37)
at Object.render (/Users/jagger/projects/jwpay/web/node_modules/mini-css-extract-plugin/dist/index.js:173:32)
at Compilation.createChunkAssets (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:2429:29)
at hooks.optimizeTree.callAsync.err (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:1299:10)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:9:1)
at AsyncSeriesHook.lazyCompileHook (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/Hook.js:154:20)
at Compilation.seal (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:1244:27)
at hooks.make.callAsync.err (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compiler.js:624:17)
at _err0 (eval at create (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:11:1)
at Promise.all.then (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/DynamicEntryPlugin.js:74:20)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
Error: chunk commons [mini-css-extract-plugin]
Conflicting order between:
* css ./node_modules/css-loader??ref--5-1!./node_modules/less-loader/dist/cjs.js??ref--5-2!./node_modules/antd/lib/menu/style/index.less
* css ./node_modules/css-loader??ref--5-1!./node_modules/less-loader/dist/cjs.js??ref--5-2!./node_modules/antd/lib/icon/style/index.less
at MiniCssExtractPlugin.renderContentAsset (/Users/jagger/projects/jwpay/web/node_modules/mini-css-extract-plugin/dist/index.js:342:37)
at Object.render (/Users/jagger/projects/jwpay/web/node_modules/mini-css-extract-plugin/dist/index.js:173:32)
at Compilation.createChunkAssets (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:2429:29)
at hooks.optimizeTree.callAsync.err (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:1299:10)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:9:1)
at AsyncSeriesHook.lazyCompileHook (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/Hook.js:154:20)
at Compilation.seal (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:1244:27)
at hooks.make.callAsync.err (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compiler.js:624:17)
at _err0 (eval at create (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:11:1)
at Promise.all.then (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/DynamicEntryPlugin.js:74:20)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
Error: chunk commons [mini-css-extract-plugin]
Conflicting order between:
* css ./node_modules/css-loader??ref--5-1!./node_modules/less-loader/dist/cjs.js??ref--5-2!./node_modules/antd/lib/tooltip/style/index.less
* css ./node_modules/css-loader??ref--5-1!./node_modules/less-loader/dist/cjs.js??ref--5-2!./node_modules/antd/lib/icon/style/index.less
at MiniCssExtractPlugin.renderContentAsset (/Users/jagger/projects/jwpay/web/node_modules/mini-css-extract-plugin/dist/index.js:342:37)
at Object.render (/Users/jagger/projects/jwpay/web/node_modules/mini-css-extract-plugin/dist/index.js:173:32)
at Compilation.createChunkAssets (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:2429:29)
at hooks.optimizeTree.callAsync.err (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:1299:10)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:9:1)
at AsyncSeriesHook.lazyCompileHook (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/Hook.js:154:20)
at Compilation.seal (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compilation.js:1244:27)
at hooks.make.callAsync.err (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/Compiler.js:624:17)
at _err0 (eval at create (/Users/jagger/projects/jwpay/web/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:11:1)
at Promise.all.then (/Users/jagger/projects/jwpay/web/node_modules/webpack/lib/DynamicEntryPlugin.js:74:20)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
โ /
โ /_app
โ /_document
โ /_error
โ /login
โ /register
ํจํค์ง.json
{
"name": "web",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "LOG_API_REQUEST=y node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.8",
"@fortawesome/free-brands-svg-icons": "^5.5.0",
"@fortawesome/free-regular-svg-icons": "^5.5.0",
"@fortawesome/free-solid-svg-icons": "^5.5.0",
"@fortawesome/react-fontawesome": "^0.1.3",
"@zeit/next-css": "^1.0.1",
"@zeit/next-less": "^1.0.1",
"@zeit/next-sass": "^1.0.1",
"ant-design-pro": "^2.2.1",
"antd": "^3.13.2",
"babel-plugin-import": "^1.11.0",
"bootstrap": "^4.1.3",
"express": "^4.16.4",
"i": "^0.3.6",
"isomorphic-unfetch": "^3.0.0",
"less": "^3.9.0",
"less-vars-to-js": "^1.3.0",
"next": "^8.0.1",
"node-sass": "^4.10.0",
"npm": "^6.4.1",
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-redux": "^5.1.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"http-proxy-middleware": "^0.19.1",
"redux-devtools-extension": "^2.13.5"
}
}
.babelrc
{
"presets": [
"next/babel"
],
"plugins": [
[
"import",
{
"libraryName": "antd",
"style": true
},
"antd"
],
[
"import",
{
"libraryName": "ant-design-pro",
"style": true,
"camel2DashComponentName": false,
},
"ant-design-pro"
]
]
}
next.config.js
const withCSS = require('@zeit/next-css')
const withSass = require('@zeit/next-sass')
const withLess = require('@zeit/next-less')
const lessToJS = require('less-vars-to-js')
const fs = require('fs')
const path = require('path')
// fix: prevents error when .less files are required by node
if (typeof require !== 'undefined') {
require.extensions['.less'] = file => { }
}
const isProd = process.env.NODE_ENV === 'production'
module.exports = withLess(withSass(withCSS({
lessLoaderOptions: {
javascriptEnabled: true,
modifyVars: lessToJS(
fs.readFileSync(path.resolve(__dirname, './assets/antd.less'), 'utf8')
),
},
})))
@jaggerwang ๋ , ๊ทํ์ ๋ฌธ์ ๋ ๋ฌธ์ ์๊ตฌ ์ฌํญ์ ์ค์ํ์ง ์์ ์ข ๋ฃ๋์์ต๋๋ค. ๋ฌธ์ ๋์ฐ๋ฏธ ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ์์ฑํ์ญ์์ค. ๊ฐ์ฌํฉ๋๋ค!
@jaggerwang ์๋ ํ์ธ์. ํจ์จ์ ์ธ ์ปค๋ฎค๋์ผ์ด์ ์ ์ํด ํด๋น ์ด์์ ๋ํ ํน์ ํ์ ์๊ตฌ ์ฌํญ์ด ์์ผ๋ฉฐ ์๊ตฌ ์ฌํญ์ ์ถฉ์กฑํ์ง ์์ ๋ฌธ์ ๊ฐ ์๋์ผ๋ก ์ข ๋ฃ๋ฉ๋๋ค. ๋ฌธ์ ๋์ฐ๋ฏธ ๋ฅผ ํตํด ๋ฌธ์ ๋ฅผ ๋ง๋ค์ด ์ค๋ฅ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. ํ๋ ฅ ํด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!
๋ฌธ์ ์ ๋ํด ๊ทธ๋ ๊ฒ ๋์ ์๊ณ๊ฐ์ ์ค์ ํด์ผ ํฉ๋๊น? ์ด๋ ๊ฒ ์๊ฒฉํ ์๊ตฌ ์ฌํญ์ ๊ฐ์ง ์คํ ์์ค ํ๋ก์ ํธ๋ฅผ ๋ณธ ์ ์ด ์์ต๋๋ค. ๋ชจ๋ ํ๋ก์ ํธ๊ฐ ์จ๋ผ์ธ์ผ๋ก ์์ฐํ๊ธฐ ์ฌ์ด ๊ฒ์ ์๋๋๋ค. ์ด ์ปดํ์ผ ๋ฐ ํจํค์ง ์ค๋ฅ๋ ๋งค์ฐ ๋ช ํํ๊ฒ ์ค๋ช ๋์ด ์์ผ๋ฉฐ ์ฝ๊ฒ ์ฌํํ ์ ์์ต๋๋ค.
์์ธต์ ์ค๋ช ์ด ์ธ์ฌํ๊ฒ ์ค๋น๋์ด์๋ ๊ฒ์ด ์ ๊ฐ์ ๋๋ค. ๋๋ ๋ํ ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ด๋ป๊ฒ ํด๊ฒฐํ์ จ๋์?
@bluenergy๋ ํด๊ฒฐ๋์ง ์์์ง๋ง ์๋ํ๋ฏ๋ก ๋จผ์ ๋ฃ์ด ๋ณด๊ฒ ์ต๋๋ค. Antd์ ๋ฌธ์ ๋ฅผ ์ธ๊ธํ๋ ๊ฒ์ ์ ๋ง ๋ฒ๊ฑฐ๋กญ์ต๋๋ค. ๋ค๋ฅธ ์ค๋ช ์ ๋งํ๊ธฐ ์ฝ์ง๋ง ์ค์ ๋ก ์๋ํ๋ ์๋ฅผ ๋ค์ด์ผ ํฉ๋๋ค. ์ฝ๋๋ ๋น๊ณต๊ฐ์ด๋ฉฐ ์ ์ฒด ๋ฐ๋ชจ ์์ ๊ฐ ๋์ค๋ ๋ฐ ๋ง์ ์๊ฐ์ด ๊ฑธ๋ฆฝ๋๋ค. ํต์ฌ์ ์ด ๋ฌธ์ ๊ฐ ์ฌ์ฉ๋ฒ๊ณผ ๊ฑฐ์ ๊ด๋ จ์ด ์๊ณ ์ฃผ๋ก ๊ตฌ์ฑ์ ๊ดํ ๊ฒ์ด๋ฉฐ ์ฌํํ๊ธฐ ์ด๋ ต์ง ์๋ค๋ ๊ฒ์ ๋๋ค. Antd Issues๊ฐ ๊ฐ์ ๋ ๋ฒจ์ ๋ค๋ฅธ ํ๋ก์ ํธ์ ๋นํด ๋๋ฌด ์ ์ ๊ฒ์ ๋น์ฐํฉ๋๋ค.
์ด๋ ๊ฒ ์๊ฒฉํ ์๊ตฌ ์ฌํญ์ ๊ฐ์ง ์คํ ์์ค ํ๋ก์ ํธ๋ฅผ ๋ณธ ์ ์ด ์์ต๋๋ค.
์ฌ์ค ๋ฌธ์ ๋์ฐ๋ฏธ ์ ์ฒด์ ๊ฐ๋ ์ vue ์ปค๋ฎค๋ํฐ์ ๊ดํ์ ๊ธฐ๋ฐ์ ๋๊ณ ์์ต๋๋ค.
๋ฒ์ํ๋ ๋ฐ ๋ง์ ์๋์ง๊ฐ ํ์ํ๊ณ ์ฐ๋ฆฌ์ ๋ฅ๋ ฅ ๊ณผ ์๋์ง๋ ์ ํ๋์ด ์์ต๋๋ค.์ฐ๋ฆฌ๋ ๋ ๋ง์ ์ ๋ณด์ ์ฌํ ๊ฐ๋ฅํ ํผ๋๋ฐฑ์ ์ ๊ณตํ๋ ์ฌ๋๋ค์๊ฒ ์ ํ๋ ์์์ ์ฐ์ ์ํ ๊ฒ์ ๋๋ค. ๋ง์ ๋ฌธ์ (ํนํ ์นํฉ ๊ตฌ์ฑ)๊ฐ ์จ๋ผ์ธ ์ฝ๋์๋๋ฐ์ค๋ฅผ ํตํด ์ ๊ณต๋ ์ ์๋ค๋ ๊ฒ์ ์๊ณ ์์ต๋๋ค.์ด๋ฌํ ์ํฉ์์ ์ฌํํ ์ ์๋ ์ต์ํ์ git repo ์ ์ฅ์๋ฅผ ์ ๊ณตํ ์ ์์ต๋๋ค. ๊ด๋ จ ์ ๋ณด์ ์ด์ ๋ vue ์์ฑ์ You Xiaoyou๊ฐ ๋ช ํํ๊ฒ ์์ฑํ์ต๋๋ค.
Antd Issues๊ฐ ๊ฐ์ ๋ ๋ฒจ์ ๋ค๋ฅธ ํ๋ก์ ํธ์ ๋นํด ๋๋ฌด ์ ์ ๊ฒ์ ๋น์ฐํฉ๋๋ค.
์์ ํ๋ก์ ํธ๋ ๋ํ ์๊ฒฉํ ๋ฌธ์ ๋์ฐ๋ฏธ ๋ฐ ์๋ ์ข ๋ฃ ๊ธฐ๋ฅ์ ์ ๊ณตํ์ง๋ง ๋ฌธ์ ์ฒ๋ฆฌ๋ ์ฌ์ ํ ๊ฐ์ฅ ํจ์จ์ ์ธ ๊ฒ ์ค ํ๋์ ๋๋ค. ํ๋๋ ์ฐ๋ฆฌ๊ฐ ๋ ๋ถ์ง๋ฐํ๊ณ ๋ค๋ฅธ ํ๋๋ ์ปค๋ฎค๋ํฐ ํ์๋ค์ ํ์ ์ด ๋ง๊ณ ์ธ ๋ฒ์งธ๋ ์ข์ ํผ๋๋ฐฑ์ ๋น์ ๊ณผ ๋๋ฅผ ๋ ํจ์จ์ ์ผ๋ก ๋ง๋ค ์ ์์ต๋๋ค.
๋ง์ง๋ง์ผ๋ก @jaggerwang ์ ํผ๋๋ฐฑ๊ณผ ์ดํด์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
์์์ด์! ์๊ฐ๋์ค๋ ํ๋ฒ ๋ฐ์๋ณด์ธ์.
@jaggerwang @afc163 ๋ create-react-app
๋ฅผ ์ฌ์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ์ฌํํ๊ธฐ ์ํ babel-plugin-import ๋ฐ ์ง์ฐ ๋ก๋ฉ์ ์ถ๊ฐํ๊ณ antd ๊ตฌ์ฑ ์์๋ฅผ ์ฌ์ฉํ๊ธฐ ๊ฐ๋จํ๊ณ ์์ธํ ๋ ์ฝ๋๋ฅผ git ์ธ๋ถ์ ์ผ๋ก ์คํํ๊ณ yarn build
์คํํ๋ฉด ๋ค์ ๊ฒฝ๊ณ ๋ฅผ ๋ณผ ์ ์์ต๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ํ๊ธฐ ์ํด 3๊ฐ์ ์๋ฃจ์
์ ์ฐพ์์ต๋๋ค. ์ฌ์ฉ์์ ํธ์๋ฅผ ์ํด 3๊ฐ์ ๋ถ๊ธฐ๊ฐ ์์ฑ๋์์ต๋๋ค. ์กฐ์ ํ yarn build
์คํ ํ ํ๋กฌํํธ๊ฐ ๋ ์ด์ ๋ํ๋์ง ์์ต๋๋ค.
"plugins": [
[
"import",
{
"libraryName": "antd",
"libraryDirectory": "es"
}
]
]
๋ฌผ๋ก ์ด๊ฒ๋ค์ ๋์ ์ผ์์ ์ธ ํด๊ฒฐ์ฑ ์ด๋ฉฐ ํฐ ์ฌ๋๋ค์ด ์ด์ ๋ฅผ ์ค๋ช ํ๊ณ ๋ ๋ง์ ํด๊ฒฐ์ฑ ์ ์ ๊ณตํ ์ ์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
๋๋ ๋ํ์ด ๋ฌธ์ , ๋ค์ํ ์คํ์ผ์ ์ถฉ๋์ด ์์ต๋๋ค.
๋๋ ๋ํ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋์์ฃผ์ธ์!
React.lazy
๋์
ํ์ ๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ถํํ๋ ํฐ ์ฝ๋ ๊ธฐ๋ฐ์์ ๋์ ์์ค์ ์ฝ๋ ๋ถํ ์ ์์ํ์ง๋ง ์ด๋ค ๊ฐ์ ธ์ค๊ธฐ๊ฐ ์๋ชป๋ ์์๋ก ๋์ด ์๋์ง ์ถ์ ํ ์ ์์์ต๋๋ค.
๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ๋์์ ์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค. next-antd-aza-less - https://www.npmjs.com/package/next-antd-aza-less ๋ฅผ ์ถ๊ฐํ๋ฉด ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ธฐ ์์ํ์ต๋๋ค.
@lonsdale8734 ์ด ํ๋ฌ๊ทธ์ธ์ ์ถ๊ฐํ์ต๋๋ค. ์ต์ ๋ฒ์ ์ ์ฌ์ ํ ๋ฌธ์ ๊ฐ ์์ผ๋ฉด ์ ์ฅ์๋ฅผ ๋ง๋์ญ์์ค. ์ฐ๋ฆฌ๋ ๊ทธ๊ฒ์ ์ดํด๋ณผ ๊ฒ์ ๋๋ค.
antd ๊ตฌ์ฑ ์์์ ์คํ์ผ์ ๋
๋ฆฝ์ ์ด๊ณ ์คํ์ผ ํ์ผ ์์์ ๊ด๋ จ์ด ์๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด ๊ฒฝ๊ณ ๋ ๋ฌด์ํ๊ฑฐ๋ ํํฐ ๋ฅผ ์ฌ์ฉํ์ฌ ์ฝ์์์ ๊ฑด๋๋ธ ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ๊ตฌ์ฑ ์์ ๊ฐ์ ธ์ค๊ธฐ ์์๋ฅผ ์ ์งํ๋ผ๋ mini-css-extract-plugin์ ์กฐ์ธ ์ ์ฐธ์กฐํ ์ ์์ต๋๋ค.
import { Button, Table } from 'antd'; // File 1
import { Table, Button } from 'antd'; // File 2
NS
import { Button, Table } from 'antd'; // File 1
import { Button, Table } from 'antd'; // File 2
๋ค์ ์ฐธ๊ณ :์คํ์ผ์ด ๋ ๋ฆฝ์ ์ด๊ธฐ ๋๋ฌธ์ ๋์ผํ ์์ ์์ด antd ๊ตฌ์ฑ ์์๋ฅผ ๊ฐ์ ธ์ค๋ ๊ฒ์ด ์์ ํฉ๋๋ค.
@zombieJ
babel-plugin-import
์์ ์ฒ๋ฆฌํ๋ ๊ฒ์ด ๋ ๋ซ์ต๋๊น?
biz ํ๋ก์ ํธ์์ ์์๋ฅผ ๋ณ๊ฒฝํ๋ ๊ฒ์ ์๊ฐ์ด ๋๋ฌด ๋ง์ด ๊ฑธ๋ฆฝ๋๋ค.
@jaaggerwang
์ด ๋ฒ๊ทธ์ ๋ ๋ค๋ฅธ ์ด์ ๋ lib dir์์ Component๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ๋๋ฌธ์
๋๋ค.
์:
import { Button } from 'antd'
import Dropdown from 'antd/lib/dropdown'
...
๊ทธ๋ฆฌ๊ณ ๊ทํ์ ํ๋ก์ ํธ๋ babel-plugin-import
๋ฅผ ๋ ์ ๊ฒ ์ฌ์ฉํฉ๋๋ค.
์ค๋ ์ฐ๋ฆฌ๋ ์ผ์ด์ค๊ฐ mini-css-extract-plugin
๊ฒฝ๊ณ ๋ฅผ ๋ง๋ค ์ ์์์ ๋ฐ๊ฒฌํ์ต๋๋ค.
๋๋ antd์ ํจ๊ป ์ฌ์ฉ์ ์ ์ ํฌ๋ผ๋ฅผ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์ด๊ฒ์ ๋ด ์ฝ๋์ด๋ฉฐ ๋งค์ฐ ๊ฐ๋จํ๋ฉฐ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
const addMyPlugin = ๊ตฌ์ฑ => {
...
};
module.exports = ์ฌ์ ์(
์ถ๊ฐ ๋ด ํ๋ฌ๊ทธ์ธ,
fixBabelImports("๊ฐ์ ธ์ค๊ธฐ", {
๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ด๋ฆ: "antd",
๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋๋ ํ ๋ฆฌ: "es",
์คํ์ผ: ์ฌ์ค
}),
addLessLoader({
์๋ฐ์คํฌ๋ฆฝํธ ์ฌ์ฉ: ์ฐธ,
์์ ๋ณ์: {
"@primary-color": "#0A4080"
}
})
);
๊ทธ๊ฒ์ ๋ํ ํด๊ฒฐ์ฑ ์ด ์์ต๋๊น?
์ฌ๊ธฐ ์ฌ๋๋ค์ ์ ๋ฐ์ด ์ค๊ตญ์ด(๋๋ ๋ฌด์์ด๋ )๋ก ์๋ตํ๋ ๊ฒ์ ๋ณด๋ ๋ฐ๊ฐ์ต๋๋ค. ๋ค์์ ํฐ์ผ์ ์ด๋ฉด ์ดํ๋ฆฌ์์ด๋ก ๋ ๊ฒ์ ๋๋ค.
@AmazingTurtle ์๊ฒ ์ต๋๋ค. ํ์ง๋ง ๊ฐ๋ฐ์์ด๊ณ Google ๋ฒ์ญ์ ๋ํด ๋ค์ด๋ณธ ์ ์ด ์๋ค๋ฉด ๊ณค๊ฒฝ์ ์ฒํ ๊ฒ์ ๋๋ค. ํํ. ๋ชจ๋ ์ฌ๋์ด ์์ด๋ฅผ ๊ตฌ์ฌํ๋ ๊ฒ์ ์๋๋๋ค. ์ฌ์ค ๋๋ถ๋ถ์ ์ฌ๋๋ค์ ๋ง์ ํ์ง ์์ต๋๋ค...๊ธฐ๋ค๋ฆฝ๋๋ค...์ค๊ตญ์ด(๋ถ๊ฒฝ์ด).
@blujedis ๋ธ๋ผ์ฐ์ ์ ๋ด์ฅ๋ ๋ฒ์ญ ๊ธฐ๋ฅ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค(์ค๋ฅธ์ชฝ ํด๋ฆญ -> ๋ฒ์ญ). github.com์ด ์ธ์ด๋ฅผ EN์ผ๋ก ์ค์ ํ๊ธฐ ๋๋ฌธ์ EN์ ์์ค ์ธ์ด๋ก ๊ฐ์ ํ๋ฏ๋ก ์ค๊ตญ์ด๋ฅผ ๋ฒ์ญํ์ง ์์ต๋๋ค. ๋ฒ์ญ๊ฐ๋ ํ ๋ฒ์ ์ฌ๋ฌ ์ธ์ด๋ฅผ ๋ฒ์ญํ ์ ์๊ธฐ ๋๋ฌธ์ ๊ฐ ๊ฒ์๋ฌผ์ ๋ณต์ฌํ๊ณ ์๋์ผ๋ก ๋ฒ์ญํ๋ ๊ฒ์ ์ข์ํ์ง ์์ต๋๋ค.
react-app-rewired
๋๋ ์ ์ฌํ ๋ฐ ์คํฑ์ ์ฌ์ฉํ์ฌ disable mini-css-extract-plugin warning
๋ฐฉ์์ผ๋ก ์ด๋ํ๋ ์ฌ๋๋ค์ ์ํด:
"mini-css-extract-plugin": "^0.8.0"
๊ฐ ์๋์ง ํ์ธํ์ญ์์ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ์ถ๊ฐํ์ญ์์ค(์ด ๋ฒ์ ์๋ ์ฃผ๋ฌธ ๊ฒฝ๊ณ ๋ฅผ ๊ฑด๋๋ฐ๋ ์ถ๊ฐ ํ๋๊ทธ๊ฐ ์์ต๋๋ค)config-overrides.js
์ ์ด ~(๋์ฐํ ํดํน)~์ ์ถ๊ฐํ์ญ์์ค. // force react-scripts to use newer version of `mini-css-extract-plugin` and ignore css ordering warnings
// (related to issue: https://github.com/facok/create-react-app/issues/5372)
for (let i = 0; i < config.plugins.length; i++) {
const p = config.plugins[i]
if(!!p.constructor && p.constructor.name === MiniCssExtractPlugin.name) {
const miniCssExtractOptions = {...p.options, ignoreOrder: true}
config.plugins[i] = new MiniCssExtractPlugin(miniCssExtractOptions)
break
}
}
๋ฉ๋ด, ๋๋กญ๋ค์ด, ํดํ ๊ฐ์ ๋ฌธ์ ๊ฐ ์ถฉ๋ํ์ฌ ๋๋กญ๋ค์ด์ ์ธ๋ถ๋ก ์ฎ๊ฒผ์ต๋๋ค. ์ง๊ธ ์๋ ์ค์ ๋๋ค
์์
import { Menu, Dropdown, Button, Icon } from 'antd';
NS
import { Menu, Button, Icon } from 'antd';
import Dropdown from 'antd/lib/dropdown';
์๋ฃจ์
์ด ๋ชจ๋ antd ๊ตฌ์ฑ ์์์ ๊ฐ์ ธ์ค๊ธฐ๋ฅผ ์ ๋ ฌํ๋ ๊ฒ์ฒ๋ผ ์ฝ์ต๋๊น?
์ด๊ฑฐ ๋ค์ ์ด์ด๋ ๋ ๊น์?!
@zombieJ ์๋ฃจ์ ์ด ํญ์ ์๋ํ๋ ๊ฒ์ ์๋๋๋ค. ์๊ท๋ชจ ํ๋ก์ ํธ์ ๋ชจ๋ ๊ฐ์ ธ์ค๊ธฐ๋ฅผ ์ผ๊ด์ฑ ์๊ฒ ๊ตฌ์ฑํ์ง๋ง ์ฌ์ ํ ์ด ๋ฌธ์ ๊ฐ ํ์๋ฉ๋๋ค.
๋ค์ ์ด์ด์ฃผ์ธ์...
Gastby ํ๋ก์ ํธ์์ ์ด์ ๋์ผํ ๋ฌธ์ ๋ฅผ ๋ณด๊ณ ์์ต๋๋ค. ๋ฐ๋ผ์ Create React App๋ง์ด ์๋๋๋ค.
@ChuckJonas์ ๋์ํฉ๋๋ค. ๋ค์ ์ด์ด์ฃผ์ธ์.
@zombieJ ,
์์ ํ์ ์ํ๋ฒณ์์ผ๋ก ๋์ดํ๋ ๊ฒ๋ง์ผ๋ก๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ๋๋ ์ด๋ฏธ ์ด๊ฒ์ ํ๊ณ ์๋ค(Prettier/ESLint๋ฅผ ํตํด):
๊ทธ๋ฆฌ๊ณ ๋๋ ๋ฌธ์ ๊ทธ๋๋ก ์ด๋ฌํ ๊ฒฝ๊ณ ์ ํ์ด์ง ๋ฅผ ๋ฐ๊ณ ์์ต๋๋ค.
์ค๋ฅ๋ฅผ ์จ๊ธฐ๊ธฐ ์ํด webpack-filter-warnings-plugin ์ ์ค์น
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
module.exports = {
// ... rest of webpack config
plugins: [
new FilterWarningsPlugin({
exclude: /Conflicting order/,
})
]
}
์ฑ์ด ์ค์ ๋ก 100% ์ ๋๋ก ๋ณด์ด๋๋ก ํ๋ ค๋ฉด ๊ฒฝ๊ณ ๋ฅผ ์จ๊ธฐ๋ ๊ฒ์ ์ข์ ์๊ฐ์ด ์๋๋๋ค. ๋ด๊ฐ ์ฐพ์ ์ ์ผํ ์ค์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ babel ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๋ ๋์ ์ ์ฒด ์คํ์ผ์ํธ๋ฅผ ๊ฐ์ ธ์ค๋ ๊ฒ์ ๋๋ค.
๋ค์์ ์ป์๋ค
ํด๊ฒฐ์ฑ ์ ์ฐพ์์ต๋๊น?
๋ด ์์ฉ ํ๋ก๊ทธ๋จ ๋ด์์ antd ๊ตฌ์ฑ ์์๋ฅผ ์ง์ฐ ๋ก๋ํ์ฌ ์ด ์ค๋ฅ๋ฅผ ์ฐํํ ์ ์์ต๋๋ค. NextJS์ ์๋ ์ด๋ฌํ ๋ฐฉ์์ผ๋ก ๋ก๋ํ๋ ๊ฒ์ ๋๋ค.
const Menu = dynamic(() => import('antd/lib/menu'))
const MenuItem = dynamic(() => import('antd/lib/menu/MenuItem'))
์ฌ๊ธฐ์์ antd์ ๋ฉ๋ด ๋ฐ ๋ฉ๋ด ํญ๋ชฉ์ ์ ์๋ฆฌ์ ์ฌ์ฉํ๊ฑฐ๋ MenuItem
๊ฐ Menu.Item
import {Menu} from 'antd'
๊ตฌ๋ฌธ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ง๊ธ๊น์ง ์คํ์ผ ๊ฐ์ ์ถฉ๋ ์์ ๋ฌธ์ ๋ ์์ต๋๋ค."
์ด๋ less๋ฅผ ์ฌ์ฉํ๊ณ babel-import-plugin์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์ ์ ์ฉ๋ฉ๋๋ค.
๋ฉ๋ด, ๋๋กญ๋ค์ด, ํดํ ๊ฐ์ ๋ฌธ์ ๊ฐ ์ถฉ๋ํ์ฌ ๋๋กญ๋ค์ด์ ์ธ๋ถ๋ก ์ฎ๊ฒผ์ต๋๋ค. ์ง๊ธ ์๋ ์ค์ ๋๋ค
์์
import { Menu, Dropdown, Button, Icon } from 'antd';
NS
import { Menu, Button, Icon } from 'antd'; import Dropdown from 'antd/lib/dropdown';
์ด๊ฒ์ ๋ค์๊ณผ ๊ฐ์ด antd/lib/button
์ ๋ณ๋๋ก ๋ชจ๋ Button
๋ฅผ ๊ฐ์ ธ์์ ์ ์๊ฒ ํจ๊ณผ์ ์ด์์ต๋๋ค.
import { Form, Input, Row, Col } from 'antd'
import Button from 'antd/lib/button'
@phatranky๋ ๊ฐ์ฌํฉ๋๋ค
Antd์ ๊ด๋ จ๋ ๊ฒฝ์ฐ ๋ค์ ๋ ๊ฐ์ง๋ฅผ ์ํํ์ญ์์ค.
babel-plugin-import์ style
์ต์
์ ์ง์ ํ์ฌ ์คํ์ผ์ ๊ฐ์ ธ์ค๋ ๊ฒฝ์ฐ 'css'
์์ true
ํ๋ฉด less
๋ฒ์ ์ ๊ฐ๋ฏธ
๋น์ ์ ์คํ์ผ์ ๊ฐ์ ธ ์ค๋ ๊ฒฝ์ฐ 'antd/dist/antd.css'
,๋ก ๋ณ๊ฒฝ antd/dist/antd.less
.
next.config.js
๋ถ๋ถ์ this nextjs-css-less-antd ์์ ํ์ธํ ์ ์์ต๋๋ค.
๋ฉ๋ด, ๋๋กญ๋ค์ด, ํดํ ๊ฐ์ ๋ฌธ์ ๊ฐ ์ถฉ๋ํ์ฌ ๋๋กญ๋ค์ด์ ์ธ๋ถ๋ก ์ฎ๊ฒผ์ต๋๋ค. ์ง๊ธ ์๋ ์ค์ ๋๋ค
์์
import { Menu, Dropdown, Button, Icon } from 'antd';
NS
import { Menu, Button, Icon } from 'antd'; import Dropdown from 'antd/lib/dropdown';
๊ฐ์ฌ ํด์! ๋๋ฅผ ์ํด ์๋ํฉ๋๋ค. ์ถฉ๋ํ๋ ๊ตฌ์ฑ ์์๋ ๋ณ๋๋ก ๊ฐ์ ธ์์ผ ํฉ๋๋ค. ์ ์๊ฒ๋ ์๋ 3๊ฐ์ง ๊ตฌ์ฑ ์์๊ฐ ์ถฉ๋ํ๋ฏ๋ก ๋ค์๊ณผ ๊ฐ์ด ๊ฐ์ ธ์ต๋๋ค.
import { Button } from 'antd';
import Modal from 'antd/lib/modal';
import message from 'antd/lib/message';
์, ์ถํ๊ณ ์ด๋ฆฌ์์ ๊ฒ์ฒ๋ผ ๋ณด์ด์ง๋ง ๊ทธ๊ฒ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ์ ์ผํ ๋ฐฉ๋ฒ์ด๋ผ๋ ๊ฒ์ ์๋๋ค.
๋ฉ๋ด, ๋๋กญ๋ค์ด, ํดํ ๊ฐ์ ๋ฌธ์ ๊ฐ ์ถฉ๋ํ์ฌ ๋๋กญ๋ค์ด์ ์ธ๋ถ๋ก ์ฎ๊ฒผ์ต๋๋ค. ์ง๊ธ ์๋ ์ค์ ๋๋ค
์์import { Menu, Dropdown, Button, Icon } from 'antd';
NS
import { Menu, Button, Icon } from 'antd'; import Dropdown from 'antd/lib/dropdown';
๊ฐ์ฌ ํด์! ๋๋ฅผ ์ํด ์๋ํฉ๋๋ค. ์ถฉ๋ํ๋ ๊ตฌ์ฑ ์์๋ ๋ณ๋๋ก ๊ฐ์ ธ์์ผ ํฉ๋๋ค. ์ ์๊ฒ๋ ์๋ 3๊ฐ์ง ๊ตฌ์ฑ ์์๊ฐ ์ถฉ๋ํ๋ฏ๋ก ๋ค์๊ณผ ๊ฐ์ด ๊ฐ์ ธ์ต๋๋ค.
import { Button } from 'antd'; import Modal from 'antd/lib/modal'; import message from 'antd/lib/message';
์, ์ถํ๊ณ ์ด๋ฆฌ์์ ๊ฒ์ฒ๋ผ ๋ณด์ด์ง๋ง ๊ทธ๊ฒ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ์ ์ผํ ๋ฐฉ๋ฒ์ด๋ผ๋ ๊ฒ์ ์๋๋ค.
์, Modal์ ๋ณ๋๋ก ๊ฐ์ ธ์ฌ ๋ ๊ฒฝ๊ณ ๊ฐ ์ฌ๋ผ์ก์ต๋๋ค.
import Modal from 'antd/lib/modal/Modal'
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ฌ๊ธฐ ์ฌ๋๋ค์ ์ ๋ฐ์ด ์ค๊ตญ์ด(๋๋ ๋ฌด์์ด๋ )๋ก ์๋ตํ๋ ๊ฒ์ ๋ณด๋ ๋ฐ๊ฐ์ต๋๋ค. ๋ค์์ ํฐ์ผ์ ์ด๋ฉด ์ดํ๋ฆฌ์์ด๋ก ๋ ๊ฒ์ ๋๋ค.