A high-performance webpack/Rspack loader for transforming JavaScript and TypeScript using Oxc.
- ⚡ Ultra Fast: 3-5x faster than SWC, 20-50x faster than Babel
- 🔧 TypeScript Support: Transform TypeScript to JavaScript with type stripping
- ⚛️ JSX/TSX Support: Transform React JSX with automatic runtime detection
- 🔄 React Fast Refresh: Built-in support for React development
- 📦 Small Bundle: Only 2MB vs SWC's 37MB
- 🛠️ Webpack & Rspack: Compatible with both bundlers
- 🗺️ Source Maps: Full source map support
- ⚙️ Configurable: Extensive configuration options
- 📋 tsconfig.json Support: Automatic detection and configuration from TypeScript config
- Node.js 20.19 or higher
npm install oxc-loader
# or
yarn add oxc-loader
# or
pnpm add oxc-loader
# or
bun add oxc-loader// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'oxc-loader',
options: {
// Options here
}
}
}
]
}
}// rspack.config.js
module.exports = {
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'oxc-loader',
options: {
// Options here
}
}
}
]
}
}interface OxcLoaderOptions {
// Enable source map generation (default: true)
sourcemap?: boolean
// Enable React Fast Refresh for development (default: false)
refresh?: boolean
// Automatically detect and configure JSX based on file extension (default: true)
autoDetectJsx?: boolean
// All oxc-transform options are also supported
typescript?: TypeScriptOptions
jsx?: JsxOptions
target?: string | string[]
// ... and more
}// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'oxc-loader',
options: {
typescript: {
onlyRemoveTypeImports: true,
declaration: {
stripInternal: true
}
}
}
}
}
]
}
}// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.jsx?$/,
use: {
loader: 'oxc-loader',
options: {
jsx: {
runtime: 'automatic', // or 'classic'
development: process.env.NODE_ENV === 'development',
importSource: 'react'
}
}
}
}
]
}
}// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.(jsx|tsx)$/,
use: {
loader: 'oxc-loader',
options: {
refresh: process.env.NODE_ENV === 'development',
jsx: {
runtime: 'automatic',
development: true
}
}
}
}
]
}
}oxc-loader automatically reads and applies relevant settings from your tsconfig.json file. This feature is enabled by default and helps ensure consistency between your TypeScript configuration and the transformation process.
The following TypeScript compiler options are automatically mapped to oxc-transform settings:
target: Maps to oxc-transform'stargetoptionjsx: Configures JSX transformation modejsxFactory: Sets custom JSX pragmajsxFragmentFactory: Sets custom JSX fragment pragmajsxImportSource: Sets JSX import source for automatic runtimeallowImportingTsExtensions: Enables import extension rewritingverbatimModuleSyntax: Enables type-only import removal
// webpack.config.js
const path = require('node:path')
module.exports = {
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'oxc-loader',
options: {
// Enable source maps
sourcemap: true,
// Enable React Fast Refresh in development
refresh: process.env.NODE_ENV === 'development',
// TypeScript configuration
typescript: {
onlyRemoveTypeImports: true
},
// JSX configuration (auto-detected for .jsx/.tsx files)
jsx: {
runtime: 'automatic',
development: process.env.NODE_ENV === 'development'
},
// Target modern browsers
target: ['es2020', 'chrome80', 'firefox80', 'safari14']
}
}
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx']
}
}// rspack.config.js
const path = require('node:path')
module.exports = {
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'oxc-loader',
options: {
refresh: true, // Enable React Fast Refresh
typescript: {
onlyRemoveTypeImports: true
}
}
}
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx']
}
}| Tool | Transform Speed | Memory Usage | Bundle Size | Packages |
|---|---|---|---|---|
| oxc-loader | Baseline | 51 MB | 2 MB | 2 |
| swc-loader | 3-5x slower | 67 MB | 37 MB | Multiple |
| babel-loader | 20-50x slower | 172 MB | 21 MB | 170+ |
Benchmarks based on oxc-project/bench-transformer
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
- loader: 'babel-loader',
+ loader: 'oxc-loader',
options: {
- presets: [
- '@babel/preset-env',
- '@babel/preset-react',
- '@babel/preset-typescript'
- ]
+ jsx: {
+ runtime: 'automatic'
+ },
+ typescript: {
+ onlyRemoveTypeImports: true
+ }
}
}
}
]
}
}// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
- loader: 'swc-loader',
+ loader: 'oxc-loader',
options: {
- jsc: {
- parser: {
- syntax: 'typescript',
- tsx: true
- },
- transform: {
- react: {
- runtime: 'automatic'
- }
- }
- }
+ jsx: {
+ runtime: 'automatic'
+ },
+ typescript: {
+ onlyRemoveTypeImports: true
+ }
}
}
}
]
}
}If you encounter native binding errors, try:
# Remove node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
# Or with pnpm
rm -rf node_modules pnpm-lock.yaml
pnpm installMake sure your tsconfig.json includes the necessary compiler options:
{
"compilerOptions": {
"jsx": "react-jsx",
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler"
}
}Contributions are welcome! Please read our contributing guide for details.
MIT License © 2024-PRESENT Sunny-117
- oxc - The JavaScript Oxidation Compiler
- oxc-transform - Standalone transform package
- webpack - Module bundler
- rspack - Fast Rust-based bundler