๋๊ท๋ชจ ํ๋ก์ ํธ๊ฐ ์๊ณ ํ ๋ฒ์ ํ ๊ตฌ์ฑ ์์๋ฅผ Typescript๋ก ๋ง์ด๊ทธ๋ ์ด์ ํ๊ธฐ ์์ํ๋ ค๊ณ ํฉ๋๋ค.
--with-typescript๋ฅผ ์๋ํ์ง๋ง ํ ๋ฒ์ ๋ชจ๋ ํ์ผ์ ์ด๋ฆ์ ๋ฐ๊ฟ์ผ ํฉ๋๋ค. ์ ํ์ผ์ด typescript ํ์ผ ํ์ฅ์๋ฅผ ์ฑํํ๋ ๋์ ๋ณํ๋์ง ์์ ํ์ผ์ด ์ด๊ธฐ ํ์ฅ์๋ฅผ ์ ์งํ๋๋ก ์ฒ์ฒํ ๋ณํํ๊ณ ์ถ์ต๋๋ค.
razzle์์๋ ์ด๋ป๊ฒ ํด์ผ ํ๋์?
์๋
ํ์ธ์, ์ ๋ with-typescript
์์ ๋ฅผ jsx
ํ์ผ๊ณผ ํจ๊ป ์ฌ์ฉํ์ฌ ๊ธฐ์กด ํ๋ก์ ํธ์ ์ ์ง์ ๋ง์ด๊ทธ๋ ์ด์
์ ํ์ฉํ๋ ๋ฐ ์ด๋ ค์์ ๊ฒช๊ณ ์์ต๋๋ค.
๋๊ตฌ๋ ์ง ์ด ๋ชฉํ๋ฅผ ๋ณด๊ดํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์์ด๋์ด๊ฐ ์์ต๋๊น?
์์๋์ด!
npm i -D @babel/preset-typescript ts-loader typescript
.babelrc์ @babel/typescript
์ถ๊ฐ
"presets": [
"razzle/babel",
"@babel/typescript"
]
์ด๊ฒ์ razzle.config.js์ ์ถ๊ฐํ์ญ์์ค.
config.resolve.extensions = config.resolve.extensions.concat(['.ts', '.tsx']);
config.module.rules.push({ test: /\.tsx?$/, loader: 'ts-loader' });
tsconfig.json ์์ฑ
{
"compilerOptions": {
"experimentalDecorators": true,
// Target latest version of ECMAScript.
"target": "esnext",
// Search under node_modules for non-relative imports.
"moduleResolution": "node",
// Process & infer types from .js files.
"allowJs": false,
// Enable strictest settings like strictNullChecks & noImplicitAny.
"strict": false,
// Disallow features that require cross-file information for emit.
"isolatedModules": true,
// Import non-ES modules as default imports.
"esModuleInterop": true,
"jsx": "react"
},
"include": [
"src"
],
"exclude": [
"node_modules",
]
}
์ด์ ํ์ฅ๋ช ์ .ts ๋ฐ .tsx๋ก ๋ณ๊ฒฝํ์ฌ ํด๋น ํ์ผ์ ๋ํ typescript๋ฅผ ํ์ฑํํ ์ ์์ต๋๋ค.
๋ฏธ๋์์ ์ฌ๊ธฐ๋ก ์ค๋ ๊ฒฝ์ฐ ์ฌ๊ธฐ์์ ํ๋ฅญํ razzle ์ง์ typescript ํ๋ฌ๊ทธ์ธ์ ํ์ธ ํ์ญ์์ค .
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์์๋์ด!
npm i -D @babel/preset-typescript ts-loader typescript
.babelrc์
@babel/typescript
์ถ๊ฐ์ด๊ฒ์ razzle.config.js์ ์ถ๊ฐํ์ญ์์ค.
tsconfig.json ์์ฑ
์ด์ ํ์ฅ๋ช ์ .ts ๋ฐ .tsx๋ก ๋ณ๊ฒฝํ์ฌ ํด๋น ํ์ผ์ ๋ํ typescript๋ฅผ ํ์ฑํํ ์ ์์ต๋๋ค.