강의

멘토링

커뮤니티

Inflearn Community Q&A

shs07078392's profile image
shs07078392

asked

[React Part 2] Advanced Topics and Hooks

[Chapter 1.2 Product List Screen] 1.2.10 ProductPage

ProductPage import 할 때, from index.jsx가 아닌 이유

Resolved

Written on

·

300

0

안녕하세요.

강의 재밌게 듣고 있습니다!

 

App.jsx에서 import ProductPage from "./pages/ProductPage" 부분에서 실제 코드는 index.jsx에 작성되어 있는데 디렉터리명인 ProductPage로 경로를 지정해도 동작하는 이유가 궁금합니다.

 

reactReact-Contextreact-hooksreact-routerreact-component

Answer 1

0

jeonghwan님의 프로필 이미지
jeonghwan
Instructor

웹팩이 자바스크립트를 포함한 프로젝트 파일을 모듈로 로드합니다. 웹팩은 노드 js 환경에서 동작하는데요. 웹팩이 모듈을 로드하는 방식 때문입니다.

  • 노드js는 "./"로 시작된 경로를 파일 혹은 디렉토리로 로드합니다.

  • 파일이 아니라서 디렉토리를 로드합니다.

  • 디렉토리에 package.json을 찾습니다.

  • 없어서 index.js를 로드합니다.

간단히 말씀드리면

  • "./pages/ProductPage" 파일이 있으면 로드하고

    없으면 그 아래 index.js를 찾는 방식을 사용합니다.

 

자세한 내용을 이 문서를 참고하시면 좋습니다.

shs07078392's profile image
shs07078392

asked

Ask a question