bp365.apps.spfx.ezuploader
v0.1.0
Published
npx create-react-app bp365.apps.spfx.exuploader --template typescript 으로 생성한 리액트는 버전 18이상 기본적을 설치됨. 그러나 SPFX는 React 17.0.1 만 지원되므로 다운그레이드 해야 함.
Readme
1. 이 컴포넌트 생성 이유
npx create-react-app bp365.apps.spfx.exuploader --template typescript 으로 생성한 리액트는 버전 18이상 기본적을 설치됨. 그러나 SPFX는 React 17.0.1 만 지원되므로 다운그레이드 해야 함.
1. 프로젝트 생성
npx create-react-app bp365.apps.spfx.exuploader --template typescript2. React18 제거/React17 설치
npm uninstall react react-dom @types/react @types/react-dom
npm install [email protected] [email protected]
npm install -D @types/[email protected] @types/[email protected]3. package.json 수정(testing-library 계열 17호환 버전으로 버전변경)
"dependencies": {
"@testing-library/react": "^12.1.5",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/user-event": "^13.5.0",
"@testing-library/dom": "^10.4.1, ==> 이 패키지는 React 17/18 버전과 무관하게 그냥 DOM API 위에서 동작하기 때문에, 굳이 변경 불필요
"react": "17.0.1",
"react-dom": "17.0.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
// React 17 프로젝트에서는 @types/[email protected] / @types/[email protected] 꼭 추가해야 합니다
"devDependencies": {
"@types/react": "17.0.53",
"@types/react-dom": "17.0.19",
"typescript": "^4.9.5"
}
chat-gpt 관련 내용
📌 Testing Library 패키지별 React 의존성
@testing-library/react
→ React에 직접 의존. React 버전에 맞춰서 선택해야 함.
React 17 → ^12.x
React 18 → ^13.x ~ ^16.x
@testing-library/jest-dom
→ Jest용 매처 확장. React 의존 없음 → 최신 유지 가능.
@testing-library/user-event
→ DOM 이벤트 시뮬레이션. React peer 없음 → 최신 유지 가능.
@testing-library/dom
→ DOM Testing Library의 코어. React peer 없음 → 최신 유지 가능.4. 모듈 재설치
Remove-Item -Recurse -Force node_modules // node_modules 삭제 Remove-Item -Force package-lock.json //package-lock.json 삭제 npm install // 전체 모듈 재설치
5. 랜더링 방식 변경
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById("root")!);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
)
아래처럼 변경해야 됨
import React from "react";
import ReactDOM from "react-dom"; // 변경해야 됨
import App from "./App";
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);6. 최초 빌드 및 테스트
npm run build // 브라우저로 정상적으로 오픈되지는 체크
// 명령어 모음.
npm run build
npm start
npm run rollup
npm publish7. package.json에 peerDependencies 추가해서 react 버전 제한 시킴
"peerDependencies": {
"react": "17.0.1",
"react-dom": "17.0.1"
},
sideEffects: false → 트리 쉐이킹 최적화8. tsconfig.json 변경
"jsx": "react" 이렇게 변경해야 함.
9. rollup 설치및 환경설정
ROLLUP설치
npm install [email protected] --save-dev npm install @rollup/[email protected] --save-dev npm install @rollup/[email protected] --save-dev npm install @rollup/[email protected] --save-dev npm install [email protected] --save-dev npm install [email protected] --save-dev npm install [email protected] --save-dev npm install [email protected] --save-dev npm install [email protected] --save-dev npm install @rollup/[email protected] --save-dev
components 폴더 만들고 CommonUtil.ts, EzUploader.types.ts, EzUploaderLanguage.ts 기존 소드되고 그냥 같다 붙이면 됨 EzUploader.tsx 파일에는 최소한의 내용만 일다 넣음 (롤업이 되는지 체크)
import React from 'react'; import {EzUploaderProps} from "./EzUploader.types";
export function EzUploader(props:EzUploaderProps) {
return(
<div id={props.clientId}>
<div> teste222 </div>
</div>
) } export default EzUploader; export type { EzUploaderProps, FileInfo, ErrorInfo} from "./EzUploader.types";
src 폴더에 index.ts 파일 생성
export { default as EzUploader } from './components/EzUploader'; export type { EzUploaderProps, FileInfo, ErrorInfo } from "./components/EzUploader.types";
Getting Started with Create React App
This project was bootstrapped with Create React App.
Available Scripts
In the project directory, you can run:
npm start
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
npm test
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
npm run build
Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
npm run eject
Note: this is a one-way operation. Once you eject, you can’t go back!
If you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
Learn More
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
