DEVLOG
Uncaught TypeError: ZNe is not a function / vite + antd build ์๋ฌ ๋ณธ๋ฌธ
Uncaught TypeError: ZNe is not a function / vite + antd build ์๋ฌ
meroriiDev 2023. 5. 15. 17:08
๐ ๋ชฉ์ฐจ
๐ก ์ด์
Uncaught TypeError: ZNe is not a function
ํ์ด์ง๋ฅผ ๋ก์ปฌ์์ ํ์ธํ ๋(yarn start)์๋ ๋ฌธ์ ๊ฐ ์๊ณ , ํ์ด์ง๋ฅผ buildํ๋ ๊ฒฝ์ฐ build์๋ ์ฑ๊ณตํ์ง๋ง ํ์ด์ง๋ฅผ ํ์ธํด๋ณด๋ฉด ์๋์ ๊ฐ์ ์๋ฌ๋ฉ์ธ์ง์ ํจ๊ป ํ์ด์ง๊ฐ ๋์์ง์ง ์๋ ์ด์ ๋ฐ์
๐ก ์์ธ
ํ์ฌ ๋ฒ๋ค๋ฌ๋ก vite๋ฅผ ์ฌ์ฉํ๊ณ ์๋๋ฐ vite+react์ ํธํ์ด ์์ง ์ ์์ ์ผ๋ก ์ด๋ฃจ์ด์ง์ง์์ ๋น๋ ์ antd ๋ถ๋ถ์์ ์ถฉ๋์ด ๋ฐ์ํ ๊ฒ์ผ๋ก ๋ณด์.
๐ก ํด๊ฒฐ
โ ํด๊ฒฐ1
(ํด๋น ์ด์๊ฐ ์ด ๋ฐฉ๋ฒ์ผ๋ก ํด๊ฒฐ๋์ง๋ ์์์ผ๋, ๋ค๋ฅธ ํ์ด์ง์์ ์ด ๋ฐฉ๋ฒ์ผ๋ก ๋น์ทํ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์ด ํจ๊ป ์ ์ฉํ๊ณ ๊ธฐ๋ก์ฉ์ผ๋ก ์์ฑํฉ๋๋ค.)
vite.config.ts์์ ์ฌ์ฉํ๋ vite-plugin-import2๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ vite-plugin-imp๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ๋ณ๊ฒฝ ํ ํด๋น ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ง๋ ์ฌ์ฉ๋ฒ์ผ๋ก ํ์ผ๋ด์ฉ์ ๋ณ๊ฒฝํจ
vite.config.ts
import { defineConfig } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
import tsconfigPaths from 'vite-tsconfig-paths';
import vitePluginImp from 'vite-plugin-imp';
// https://vitejs.dev/config/
export default defineConfig({
server: {
port: 8080,
},
mode: process.env.VITE_APP_MODE,
envDir: 'config',
build: {
chunkSizeWarningLimit: 2500,
cssCodeSplit: true,
outDir: 'build',
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
modifyVars: {
'@primary-color': '#5a74f5',
},
},
},
},
resolve: {
alias: [{ find: /^~/, replacement: '' }],
},
plugins: [
reactRefresh(),
tsconfigPaths(),
vitePluginImp({
libList: [
{
libName: 'antd',
style: name => `antd/es/${name}/style`,
},
],
}),
],
});
โญ๏ธ ํด๊ฒฐ2
ํด๋น ์ด์์ ์ง์ ์ ์ธ ํด๊ฒฐ๋ฐฉ๋ฒ์ผ๋ก vite์ antd ์ฌ์ด์ ๋ฐ์ํ๋ ์ถฉ๋์ด์๋ import ๋ถ๋ถ์ ๋ณ๊ฒฝ
components/Tables/Metatable
๊ธฐ์กด์๋ antd/lib/table์์ Table๊ณผ TableProps๋ฅผ ์๋์ ๊ฐ์ ๋ฐฉ์์ผ๋ก importํ๊ณ ์๋๋ฐ ์ด๋ antd/lib/table์์ importํ๊ณ ์๋ Table ์ปดํฌ๋ํธ๊ฐ ๋ฌธ์ ๊ฐ ๋์๋ค.
ํด๋น ์ปดํฌ๋ํธ๋ฅผ ์๋์ ๊ฐ์ ๋ฐฉ์์ผ๋ก antd๋ด์์ ๊ฐ์ฒดํ์์ผ๋ก Table์ ๊ฐ์ ธ์ค๋ build์ ๋ฐ์ํ๋ ์๋ฌ๊ฐ ํด๊ฒฐ๋์๋ค.
๐ก ์ ๋ฆฌ
vite์ antd๋ฅผ ํจ๊ป ์ฌ์ฉํ ๋๋ antd ์์๋ 'antd'์์ ๊ฐ์ฒดํ์์ผ๋ก,
antd type์์๋ 'antd/lib/...'์์ ๊ฐ์ฒดํ์์ผ๋ก import ํ๋ ๋ฐฉ์์ ์ด์ฉ!
์ฌ์ฉ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ฒ์ ์ ๋ณด
"antd": "^4.16.13",
"vite": "^2.9.0",
"vite-plugin-imp": "^2.2.0"