절대경로, 상대경로
React absolute / relative path
relative path(상대경로)
import styles from '../../../styles';
이런 구조라면
import하기 복잡하고 힘들어진다.
absolute path(절대경로)
import styles from 'styles';
Use absolute path(src 기준)
-
Babel Plugin
"plugins": [
[
"module-resolver",
{
"alias": {
"~/*": "./src"
}
}
],
...
]
-
Webpack
resolve: {
modules: [
path.join(__dirname,"src"),
"node_modules"
]
}
-
Package.json
"scripts": {
"start": "REACT_APP_ENV=development NODE_PATH=./src react-scripts start",
"build": "REACT_APP_ENV=production NODE_PATH=./src react-scripts build",
...
},
VSCode path(파일 추적 가능하도록)
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [
"*",
"src/*"
]
}
}
}
댓글
댓글 쓰기