@rechunk/babel-plugin
Version:
Babel plugin for transforming and processing ReChunk directives in React Native applications
139 lines (101 loc) • 2.48 kB
Markdown
Babel plugin for transforming and processing ReChunk directives in React Native applications.
- 🎯 Transforms `use rechunk` directives
- 🔄 Automatic code splitting support
- ⚡️ Dynamic imports generation
- 🛡️ Secure token handling
- 🔍 Path alias resolution
- 📦 React Native optimization
```bash
npm install --save-dev @rechunk/babel-plugin
yarn add -D @rechunk/babel-plugin
pnpm add -D @rechunk/babel-plugin
```
```javascript
// babel.config.js
module.exports = {
plugins: ['@rechunk/babel-plugin'],
};
```
```javascript
// babel.config.js
const {withReactNativeBabelPresetOptions} = require('@rechunk/babel-plugin');
module.exports = {
presets: [
[
'module:metro-react-native-babel-preset',
api => withReactNativeBabelPresetOptions(api),
],
],
plugins: ['@rechunk/babel-plugin'],
};
```
```javascript
// babel.config.js
const {withBabelPresetExpoOptions} = require('@rechunk/babel-plugin');
module.exports = {
presets: [['babel-preset-expo', api => withBabelPresetExpoOptions(api)]],
plugins: ['@rechunk/babel-plugin'],
};
```
```tsx
// Input
'use rechunk';
export default function MyComponent() {
return <View>...</View>;
}
// Output
import React from 'react';
import {importChunk} from '@rechunk/core';
const $$ReChunkModule = React.lazy(() => importChunk('base64-encoded-path'));
export default $$ReChunkModule;
```
```bash
RECHUNK_ENVIRONMENT=prod
RECHUNK_ENVIRONMENT=dev
RECHUNK_ENVIRONMENT=offline
```
```json
{
"host": "https://your-rechunk-host.com",
"project": "your-project-id",
"readKey": "your-read-key",
"publicKey": "your-public-key",
"external": ["optional-external-dependency"]
}
```
```typescript
function withReactNativeBabelPresetOptions(
api: ConfigAPI,
options: Record<string, unknown> = {},
): Record<string, unknown>;
```
```typescript
function withBabelPresetExpoOptions(
api: ConfigAPI,
options: BabelPresetExpoOptions = {},
): BabelPresetExpoOptions;
```
Contributions are welcome! Please read our contributing guidelines first.
MIT