콘텐츠로 이동

Rspack / Webpack 통합

@zntc/rspack-loader 는 Rspack 과 Webpack 5 의 loader API 로 동작하는 변환기입니다. swc-loader, esbuild-loader, babel-loader 자리에 그대로 끼워 ZNTC (Zig 기반 트랜스파일러) 로 TypeScript / JSX / Flow / decorator 변환을 처리합니다.

builtin:swc-loader 자리에 그대로 대체할 수 있으며 (loader API 가 webpack/rspack 공통이라) 동일 코드로 양쪽 번들러에서 동작합니다.

Terminal window
bun add -D @zntc/rspack-loader @zntc/core
# 또는
npm i -D @zntc/rspack-loader @zntc/core

@zntc/core 가 dependency 로 함께 따라옴 (NAPI binary 포함).

rspack.config.mjs
export default {
module: {
rules: [
{
test: /\.(?:tsx?|jsx?)$/,
exclude: /node_modules/,
loader: '@zntc/rspack-loader',
options: {
transpileOptions: { target: 'es2020', jsx: 'automatic' },
},
},
],
},
};
webpack.config.mjs
export default {
module: {
rules: [
{
test: /\.(?:tsx?|jsx?)$/,
exclude: /node_modules/,
use: {
loader: '@zntc/rspack-loader',
options: {
transpileOptions: { target: 'es2020', jsx: 'automatic' },
},
},
},
],
},
};
interface ZntcLoaderOptions {
transpileOptions?: Omit<TranspileOptions, 'filename'>;
tsconfigCache?: boolean;
}

tsconfig autodiscover walk 결과를 worker 별로 캐시. dev/watch 세션에서 같은 워크스페이스 안 파일은 한 번만 walk → file 당 5–10 fs syscall 절약. transpileOptions.tsconfigPath / tsconfigRaw 명시 시 자동 무시.

@zntc/coreTranspileOptions 와 동일 (filename 만 loader 가 this.resourcePath 로 자동 채움). 전체 옵션은 Transpile 옵션 레퍼런스 또는 @zntc/core 참고.

자주 쓰는 옵션:

옵션타입설명
target'es5' | 'es2015' | ... | 'esnext'ES 다운레벨 타겟
browsersliststring | string[]browserslist 쿼리 (지정 시 target 보다 우선)
platform'browser' | 'node' | 'neutral' | 'react-native'타겟 플랫폼
format'esm' | 'cjs'모듈 포맷
jsx'classic' | 'automatic' | 'automatic-dev'JSX 런타임
jsxImportSourcestringautomatic import source (default react)
tsconfigPathstringtsconfig.json 경로
tsconfigRawstringinline tsconfig JSON
flowbooleanFlow 타입 스트리핑
experimentalDecorators / emitDecoratorMetadatabooleanlegacy decorator
defineArray<{ key, value }>식별자 치환 (value 는 raw JSON)
sourcemapboolean소스맵 생성
minify / dropConsole / dropDebuggerboolean산출물 축소

예시 — define 으로 환경변수 치환

섹션 제목: “예시 — define 으로 환경변수 치환”
{
loader: '@zntc/rspack-loader',
options: {
transpileOptions: {
define: [
{ key: 'process.env.NODE_ENV', value: '"production"' },
{ key: '__DEV__', value: 'false' },
],
},
},
}
{
test: /\.js$/,
loader: '@zntc/rspack-loader',
options: { transpileOptions: { flow: true, jsx: 'automatic' } },
}
{
loader: '@zntc/rspack-loader',
options: {
transpileOptions: {
tsconfigPath: './tsconfig.json',
experimentalDecorators: true,
emitDecoratorMetadata: true,
},
},
}
  • @rspack/core >= 1.0.0 (optional, rspack 1.x / 2.x 지원)
  • webpack >= 5.0.0 (optional)

둘 중 하나만 설치돼있어도 동작.

Rspack 의 builtin:swc-loader 는 Rust 로 컴파일돼 rspack core 안에 들어 있어 외부 패키지가 같은 prefix 로 등록할 수 없습니다. @zntc/rspack-loader 는 esbuild-loader 와 동일한 일반 JS loader 모델로 NAPI 를 통해 ZNTC native binary 를 호출합니다.