Next.js์ ์ปดํ์ผ๋ฌ๋ ๋ฐ๋ฒจ ๋์ ์ Rust ๊ธฐ๋ฐ์ SWC๋ฅผ JS ๋ฒ๋ค๋ง์ ์ฌ์ฉํ๋ค. ์ด๋ ๋ฐ๋ฒจ๋ณด๋ค 17๋ฐฐ ๋น ๋ฅด๋ฉฐ, Next.js 12๋ถํฐ ๋ํดํธ๋ก ์ฐ์ธ๋ค. ๋ง์ฝ ๋ฐ๋ฒจ์ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด, ๋ค์์ ์ฐธ๊ณ ํ๋ฉด ๋๋ค.
Next.js Compiler์ ์์ธํ ๋ด์ฉ์ ๊ณต์ ๊ฐ์ด๋์ ๋์์๋ค. ์ด ๊ธ์์๋ ์ฃผ๋ก ์ฌ์ฉํ ๋งํ ์์๋ง ์์ฝํ์ฌ ์ ๋ฆฌํ์๋ค.
Supported Features
-
Styled Components :
bebel-plugin-styled-components์ ์ฐ๊ณํ์ฌ styled-components๋ฅผ ์ํ ๋ฐ๋ฒจ ์ค์ ์ next.js compiler์์๋ ์ฌ์ฉํ ์ ์๋ค. -
Jest : css auto mocking, loading
.env๋ฑ์ ํตํด Jest๋ฅผ ์ด์ฉํ ํ ์คํธ ์ค์ ์ ๊ฐํธํ๊ฒ ํด์ค๋ค. -
Relay : Graph QL ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ธ Relay์ ๋ํ ์ค์ ์ ์ ๊ณตํ๋ค.
-
Remove React Properties :
babel-plugin-react-remove-properties์ ๋น์ทํ๊ฒ JSX ํ๋กํผํฐ๋ฅผ ์ ๊ฑฐํ๋ค. ํ ์คํ ์ ์ฉ์ดํ๋ค. -
Remove Console : ๊ฐ๋จํ ์ค์ ์ผ๋ก ๋ฏธ์ฒ ์ง์ฐ์ง ๋ชปํ ์ฝ์ ๋ก๊ทธ๋ฅผ ๋น๋๊ณผ์ ์์ ์ง์์ค๋ค.
// next.config.js module.exports = { compiler: { removeConsole: true, }, }์ผ๋ถ ๋ก๊ทธ๋
exclude๋ฅผ ํตํด ๋จ๊ธธ ์ ์๋ค.// next.config.js module.exports = { compiler: { removeConsole: { exclude: ['error'], }, }, } -
Emotion : `@emotion/babel-plugin์ ์ค์ ์ next.config.js์์ ๋์ ํ ์ ์๋ค.
-
Modularize Imports : ํจํค์ง๋ฅผ ๋ถ๋ฌ์ฌ ๋, โbarrel fileโ ์ default import ์ฒ๋ผ ์ฌ์ฉํ ์ ์๊ฒ ํด์ค๋ค.
import { Row, Grid as MyGrid } from 'react-bootstrap' -> import Row from 'react-bootstrap/Row' import MyGrid from 'react-bootstrap/Grid'
์ด๋ ๋ค์๊ณผ ๊ฐ์ด ์ค์ ํ๋ค.
// next.config.js
module.exports = {
modularizeImports: {
'react-bootstrap': {
transform: 'react-bootstrap/{{member}}',
}
}
}์ข ๋ ๋ค์ํ ์ค์ ์ ๋ณด๊ธฐ ์ํด์ ๊ณต์๋ฌธ์ ์ฐธ์กฐ
Experimental Features
-
Minifier debug options : minifier ์ต์ ์ด ์์ง ์คํ๋จ๊ณ์ด๊ธฐ ๋๋ฌธ์, ๊ทธ๋์ ๋๋ฒ๊ทธ ๋ชฉ์ ์ผ๋ก minifier์ ์ค์ ์ ๋ณ๊ฒฝํ ์ ์๋ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๋ค. minifier๊ฐ stable ๋จ๊ณ์ ๋์ ํ๋ฉด, ์ด ๋ฐฉ๋ฒ์ ์ฌ๋ผ์ง๋ค.
-
SWC Plugins : WASM๋ก ์ฐ์ฌ์ง SWC ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ์ฌ swc์ ์ฝ๋ ํธ๋์คํฌ๋ฉ์ด์ ๊ณผ์ ์ ๋ณ๊ฒฝํ ์ ์๋ค.
// next.config.js module.exports = { experimental: { swcPlugins: [ [ 'plugin', { ...pluginOptions, }, ], ], }, }swcPlugins๋ ํํ ๋ฐฐ์ด์ ๋ฐ๋๋ค. ์ฒซ๋ฒ์งธ๋ plugin์ผ๋ก์ path๋ฅผ ๋ฐ๊ณ , ๋๋ฒ์งธ๋ก๋ plugin option ์ ๋ฐ๋๋ค. ์ด๋ path๋ npm module ํจํค์ง๋ช ์ด๋.wasm๋ฐ์ด๋๋ฆฌ ํ์ผ์ ์ ๋ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ ์ ์๋ค.
Unsupported Features
๋ง์ฝ ์ดํ๋ฆฌ์ผ์ด์
์์ .babelrc๋ฅผ ๊ฐ์ง๊ณ ์๋ค๋ฉด, next.js๋ ์๋์ผ๋ก next.js compiler ๋์ Bebel์ ์ฌ์ฉํ๋ค.