설명

위의 스샷처럼
import 시 확장자(extenstion)와 index를 생략할 수 있는 편리한 옵션이 있습니다!
방법
다음과 같이 package.json의 scripts 부분을 수정합니다.
javascript
...
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "cross-env NODE_ENV=development && nodemon --experimental-specifier-resolution=node index.js",
"production": "cross-env NODE_ENV=production && pm2 start index.js"
},
...
--experimental-specifier-resolution=node
라는 옵션이 이런 편리한 기능을 제공합니다.
참고 : webpack으로 빌드하면 react처럼 이런 옵션 없이도 된다고도 합니다.
참조
ES6 (ECMAScript 2015) modules: import index.js
Looking on the Internet I'm confused with the special "index.js" module file. Using babelJS + Node.js or Browserify/Webpack I can import an "index.js" module inside a "libs...
stackoverflow.com
'개발 > node' 카테고리의 다른 글
콜백(callback) 함수를 Promise로 바꾸기 (콜백함수로 await 쓰기) (0) | 2021.07.20 |
---|---|
Mongoose 개념 및 사용법 정리 (0) | 2021.03.19 |
express에서 get, post 파라미터 가져오기 (0) | 2021.03.19 |
댓글