번들러 마이그레이션(webpack to vite) 트러블 슈팅 노트
번들러 마이그레이션 과정간 트러블 슈팅에 대한 노트를 기록했습니다.

Search for a command to run...
번들러 마이그레이션 과정간 트러블 슈팅에 대한 노트를 기록했습니다.

No comments yet. Be the first to comment.
프론트엔드는 원래도 복잡했습니다. 브라우저마다 다른 렌더링, 상태 동기화, 성능, 접근성 — 화면 하나 제대로 만드는 데 신경 쓸 게 늘 많았습니다. 다만 그 복잡함은 대체로 한 방향을 향했습니다. 이 UI를 어떻게 만들까, 상태를 어떻게 관리할까, 클릭하면 무엇이 바뀌어야 할까. 그런데 요즘 질문의 축이 하나 더 늘고 있습니다. 이 UI는 서버에서 먼저
Microsoft가 TypeScript 7.0 beta를 공개했습니다. Go로 포팅한 네이티브 컴파일러고 "약 10배 빠르다"는 게 광고 문구입니다. 그 숫자가 실제 코드베이스에서도 나오는지, 따라붙는 호환성 비용은 뭔지 직접 돌려봤습니다. 대상 프로젝트는 React 19 + Vite 5로 굴리는 SPA고 .ts/.tsx 파일은 604개, composite
프론트엔드 개발자라면 아는 고통
'더 잘 놀기위해' 나를 빚는 인간

솔직히 말하면, 요즘 PR을 제때 리뷰하지 못하고 있습니다. 개발 속도는 빨라졌는데 리뷰 속도는 그대로입니다. 예전엔 하루 이틀이면 처리하던 게 이제는 며칠씩 밀립니다. 처음엔 제가 게을러진 탓인가 싶었습니다. 돌아보니 그게 아니었습니다. AI 도구를 쓰면서 코드가 쏟아지는 속도가 달라졌습니다. 한 사람이 만들어내는 코드 양이 예전과 비교가 안 됩니다. P

번들링 속도 개선: 개발 환경에서 개발시, 배포 빌드시 속도를 개선해줍니다.
개발 환경에서의 트러블슈팅은 주로 소스 코드와 config, 패키지 변경에서 이뤄졌습니다.
index.html 위치 변경: %root_dir%/public/index.html → %root_dir%/index.html
허용되지 않는 html 파일 내 %env_variable% 제거 (참고: 4.2.0 버전부터 지원됩니다)
기본 tsx 파일(main.tsx, or index.tsx)의 script module import 추가
<script type="module" src="/src/index.tsx"></script>@import ~vite 리액트 리프레시 지원을 위해 react() → reactRefresh() 로 변경 @vitejs/plugin-react-refresh
환경 변수 이식
import { loadEnv } from 'vite';
const env = loadEnv(mode, process.cwd(), '');
// defineConfig 내 json 설정
define: {
__APP_ENV__: env.APP_ENV,
'process.env': env,
},
import { viteCommonjs } from '@originjs/vite-plugin-commonjs';
// defineConfig 내 json 설정
plugins: [viteCommonjs()]
CJS 방식 require가 코드 내에서 사용됐을 때 변경하지 못하는 이슈
회사 도메인 연관 코드는 삭제했습니다.
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const webpackDevClientEntry = require.resolve('react-dev-utils/webpackHotDevClient');
const reactRefreshOverlayEntry = require.resolve('react-dev-utils/refreshOverlayInterop');
module.exports = {
entry: './src/index.js',
output: {
path: path.join(__dirname, '/dist'),
filename: 'index_bundle.js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_module/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(svg|png|jpe?g|gif)$/i,
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputhPath: 'imgs',
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: 'public/index.html',
}),
new ReactRefreshWebpackPlugin({
overlay: {
entry: webpackDevClientEntry,
module: reactRefreshOverlayEntry,
},
}),
],
};
import { defineConfig, loadEnv } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
import viteCommonjs from 'vite-plugin-commonjs';
export default defineConfig(({ command, mode }) => {
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
const env = loadEnv(mode, process.cwd(), '');
return {
plugins: [reactRefresh(), viteCommonjs()],
root: './',
define: {
__APP_ENV__: env.APP_ENV,
'process.env': env,
},
base: '/',
build: {
outDir: './build',
manifest: true,
rollupOptions: {
input: 'index.html',
output: {
dir: './build',
format: 'esm',
},
},
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
}
};
});
개발 환경 속도 대폭 개선
번들링 속도 약 55프로 개선: 기존 평균 1분 → 33초
웹팩 관련 패키지 및 복잡한 설정(보일러 플레이트 설정..?) 제거
글 작성을 염두에 두지 못하고 뒤늦게 정리하다보니 내용이 미흡해서 아쉽네요. 누군가에게는 도움이 되길 바랍니다.