You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Webpack 설정에서 entry 포인트로 ./index를 사용하고 있는데, resolve.extensions 덕분에 index.tsx로 잘 해석되지만, 명시적으로 ./index.tsx로 지정하면 코드를 처음 보는 동료들이 더 쉽게 이해할 수 있을 것 같아요! 작은 디테일이지만 가독성을 높일 수 있답니다! 😉
document.getElementById('root')가 null을 반환할 수 있으므로, createRoot를 호출하기 전에 container 요소의 존재 여부를 명시적으로 확인해야 합니다. 현재 ! (non-null assertion) 연산자는 런타임에 null이 아님을 보장하지 않아 애플리케이션 충돌을 유발할 수 있습니다. null 체크 로직을 추가하여 안정성을 높이세요.
const container = document.getElementById('root');
-const root = createRoot(container!);+if (!container) {+ throw new Error('Root element not found');+}+const root = createRoot(container);
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a potential runtime error if the root element is not found, which the non-null assertion operator ! does not prevent. Adding an explicit null check improves the robustness of the application.
document.getElementById('root')가 null을 반환할 경우, container!와 같이 비-null 단언 연산자를 사용하면 런타임 오류가 발생할 수 있습니다. createRoot를 호출하기 전에 container 요소의 존재 여부를 확인하는 것이 안전합니다.
const container = document.getElementById('root');
-const root = createRoot(container!);+if (!container) {+ throw new Error('ID가 "root"인 루트 요소를 문서에서 찾을 수 없습니다.');+}+const root = createRoot(container);
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a potential runtime error if document.getElementById('root') returns null. Adding a check for the container element's existence improves the robustness and error handling of the application.
Medium
General
개발 스크립트 실행 방식 수정
dev 스크립트에서 build:dev와 start:dev를 동시에 실행하는 것은 의도치 않은 동작을 유발할 수 있습니다. webpack serve (start:dev)는 개발 서버를 시작하고 메모리에서 빌드를 처리하므로, 별도의 build:dev 명령을 병렬로 실행하는 것은 불필요하며 충돌을 일으킬 수 있습니다. 개발 시에는 start:dev만 실행하는 것이 일반적입니다.
-"dev": "pnpm run build:dev & pnpm start:dev"+"dev": "pnpm run start:dev"
Suggestion importance[1-10]: 8
__
Why: Running build:dev and start:dev concurrently is redundant and can cause conflicts, as webpack serve (used in start:dev) already handles the development build in memory. The suggestion correctly streamlines the development workflow.
Medium
진입점 파일 확장자 명시
resolve.extensions에 확장자가 포함되어 있어도, 진입점 파일에 명시적으로 확장자를 지정하는 것이 좋습니다. 이는 설정의 명확성을 높이고, 잠재적인 파일 이름 충돌이나 해석 순서 변경에 대한 견고성을 향상시킵니다.
entry: {
// 입력
- app: ['./index'],+ app: ['./index.tsx'],
// 파일 내부에서 다른 파일을 호출한다면, webpack이 자동으로 이를 파악해준다. 따라서 entry에 추가하지 않아도 된다.
},
Suggestion importance[1-10]: 6
__
Why: While resolve.extensions handles the file extension, explicitly stating .tsx in the entry configuration enhances clarity and maintainability, making the configuration more robust against potential resolution ambiguities.
document.getElementById('root')가 null을 반환할 경우 createRoot(container!)에서 런타임 오류가 발생할 수 있습니다. container가 존재하는지 확인하고, 존재하지 않을 경우 적절한 오류 처리 로직을 추가하는 것이 좋습니다.
-const root = createRoot(container!);+const container = document.getElementById('root');+if (!container) {+ throw new Error('Root element not found');+}+const root = createRoot(container);
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a potential runtime error if document.getElementById('root') returns null. Adding an explicit check improves the robustness and error handling of the application.
Medium
General
사용되지 않는 Webpack 플러그인을 제거합니다
LoaderOptionsPlugin은 Webpack 4/5에서 더 이상 사용되지 않는(deprecated) 플러그인입니다. 해당 플러그인의 debug 옵션 기능은 이제 mode 설정에 따라 자동으로 처리되므로 제거하는 것이 좋습니다.
Why: LoaderOptionsPlugin is deprecated in Webpack 4/5, and its debug option is automatically handled by the mode configuration. Removing this deprecated plugin improves the cleanliness and maintainability of the Webpack configuration.
Low
사용되지 않는 Babel 플러그인 의존성을 제거합니다
@babel/plugin-proposal-class-properties 플러그인은 더 이상 사용되지 않으며, @babel/preset-env가 이미 클래스 속성을 처리하므로 이 의존성은 불필요합니다. package.json에서 해당 플러그인을 제거하는 것이 좋습니다.
Why: The @babel/plugin-proposal-class-properties plugin is deprecated and its functionality is already covered by @babel/preset-env. Removing this unnecessary dependency improves project hygiene and simplifies the dependency tree.
@babel/plugin-proposal-class-properties 플러그인은 더 이상 사용되지 않습니다. 대신 @babel/plugin-transform-class-properties를 사용하여 최신 Babel 구성을 유지하고 잠재적인 호환성 문제를 방지해야 합니다. package.json의 devDependencies도 함께 업데이트해야 합니다.
Why: @babel/plugin-proposal-class-properties는 더 이상 사용되지 않으므로, @babel/plugin-transform-class-properties로 교체하는 것은 올바른 개선입니다. package.json의 devDependencies도 함께 업데이트해야 합니다.
Medium
루트 요소 존재 여부 확인
document.getElementById('root')의 결과가 null일 수 있으므로, createRoot를 호출하기 전에 container 요소의 존재 여부를 확인하는 것이 중요합니다. 이는 런타임 오류를 방지하고 애플리케이션의 견고성을 높입니다.
-const root = createRoot(container!);+if (!container) {+ throw new Error('Root element not found');+}+const root = createRoot(container);
Suggestion importance[1-10]: 8
__
Why: document.getElementById('root')가 null을 반환할 가능성이 있으므로, createRoot를 호출하기 전에 container 요소의 존재 여부를 확인하는 것은 런타임 오류를 방지하고 애플리케이션의 견고성을 높입니다.
Medium
General
더 이상 사용되지 않는 Webpack 플러그인 제거
LoaderOptionsPlugin은 Webpack 4부터 더 이상 사용되지 않으며, 로더 옵션은 직접 구성하는 것이 좋습니다. babel-loader의 debug 옵션은 이미 @babel/preset-env 설정 내에서 처리되고 있으므로, 이 플러그인은 제거하여 구성을 간소화할 수 있습니다.
-new LoaderOptionsPlugin({ debug: true }),+// new LoaderOptionsPlugin({ debug: true }),
Suggestion importance[1-10]: 7
__
Why: LoaderOptionsPlugin은 Webpack 4부터 더 이상 사용되지 않으며, babel-loader의 debug 옵션은 이미 @babel/preset-env 설정 내에서 처리되고 있습니다. 이 플러그인을 제거하여 구성을 간소화하는 것은 좋은 개선입니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement
Description
React 애플리케이션 초기 Webpack 설정 추가
Babel 및 React Refresh 플러그인 구성
개발 및 빌드 스크립트 정의
ESLint Node.js 전역 변수 지원
Diagram Walkthrough
File Walkthrough
index.tsx
React 애플리케이션 초기 컴포넌트 및 렌더링 설정apps/webpack/index.tsx
App컴포넌트를 정의했습니다.createRoot를 사용하여rootDOM 요소에 React 애플리케이션을 렌더링하도록 설정했습니다.index.html
React 애플리케이션을 위한 기본 HTML 파일 생성apps/webpack/index.html
rootdiv를 포함하는 기본 HTML 구조를 생성했습니다.app.js)을defer속성으로 로드하도록 스크립트 태그를 추가했습니다.webpack.config.js
Webpack 및 Babel을 이용한 React 개발 환경 설정apps/webpack/webpack.config.js
.js,.jsx,.ts,.tsx)를 설정했습니다.@babel/preset-env,@babel/preset-react,@babel/preset-typescript를 포함했습니다.ReactRefreshWebpackPlugin을 추가하여 HMR(Hot Module Replacement)을 활성화했습니다.devServer를 구성하여 개발 서버, HMR, 자동 브라우저 열기 기능을 제공합니다.eslint.config.js
ESLint Node.js 전역 변수 지원 추가eslint.config.js
globals.node를 추가했습니다.package.json
Webpack 빌드 스크립트 및 종속성 정의apps/webpack/package.json
start:dev,start:prod,build:dev,build:prod스크립트를 추가하여 Webpack 개발 및빌드 명령어를 정의했습니다.
react,react-dom및 Webpack 관련 개발종속성(
@pmmmwh/react-refresh-webpack-plugin,babel-loader,webpack,webpack-cli,webpack-dev-server)을 추가했습니다.