๋ฐฉ๋ฒ์ 2๊ฐ์ง๊ฐ ์์ต๋๋ค.
1. tsconfig + package.json
- tsconfig ํ์ผ์ ์ค์ ํด์ฃผ๊ณ
- path alias๋ฅผ ์ค์ ํ ๋ชจ๋ ํด๋์ package.json ํ์ผ์ ๋ง๋ค์ด์ค๋๋ค.
- ๋ชจ๋ ํด๋์ package.json ํ์ผ์ ๋ง๋ค์ด์ผ ํด์ ๋ฒ๊ฑฐ๋กญ๋ค๋ ๋จ์ ์ด ์์ต๋๋ค.
//tsconfig.json
{
"extends": "@tsconfig/react-native/tsconfig.json",
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@components/*": ["components/*"],
"@hooks/*": ["hooks/*"],
"@pages/*": ["pages/*"],
"@routes/*": ["routes/*"],
"@types/*": ["types/*"],
"@utils/*": ["utils/*"]
}
}
}
//routes ํด๋ ์์ package.json ํ์ผ
{
"name": "@routes"
}
2. tsconfig + babel.config.js
- tsconfigํ์ผ์ ์ค์ ํด์ฃผ๊ณ
- babel.config.js ํ์ผ์ ์ค์ ํด์ค๋๋ค
- ์ฌ๊ธฐ์ ์ฃผ์ํ ์ ์ babel.config.js ํ์ผ์ alias์๋ *๊ฐ ๋ค์ด๊ฐ์ง ์์ต๋๋ค.
//tsconfig.json
{
"extends": "@tsconfig/react-native/tsconfig.json",
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@components/*": ["components/*"],
"@hooks/*": ["hooks/*"],
"@pages/*": ["pages/*"],
"@routes/*": ["routes/*"],
"@types/*": ["types/*"],
"@utils/*": ["utils/*"]
}
}
}
//babel.config.js
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'module-resolver',
{
root: ['./src'],
extensions: [
'.ios.ts',
'.android.ts',
'.js',
'.ts',
'.jsx',
'.tsx',
'.json',
],
alias: {
'@components': './src/components',
'@hooks': './src/hooks',
'@pages': './src/pages',
'@routes': './src/routes',
'@types': './src/types',
'@utils': './src/utils',
},
},
],
],
};
'๐ป ํ๋ก ํธ์๋' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
CSS ์ ๋๋ฉ์ด์ ์ฑ๋ฅ ๊ฐ์ (0) | 2024.01.08 |
---|---|
[React Native] ํฐํธ ์ค์ (0) | 2024.01.05 |
[React Native] ๋ฅ๋งํฌ ์ค์ ํ๊ธฐ (0) | 2024.01.04 |
Vitest & MSW๋ฅผ ์ฌ์ฉํ ํ ์คํธ ์ฝ๋ ์ ์ฉ (1) | 2023.12.29 |
ํ์ด์ํฐ EJS -> React ๋ง์ด๊ทธ๋ ์ด์ ๊ณผ์ (~ing) (1) | 2023.12.29 |