# babel-plugin-transform-react-templates

> Babel plugin to register react templates with a global function

Latest version **1.0.0** (published 2026-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-transform-react-templates
pnpm add babel-plugin-transform-react-templates
yarn add babel-plugin-transform-react-templates
bun add babel-plugin-transform-react-templates
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: no vulnerabilities; has provenance.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2026-02-11 |
| First published | 2020-07-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Maintainers | oliverfoster, oliver.foster, taylortom, bradsimpsonkineo |
| Keywords | babel-plugin |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-react-templates
- Repository: https://github.com/cgkineo/babel-plugin-transform-react-templates
- Homepage: https://github.com/cgkineo/babel-plugin-transform-react-templates#readme
- Issues: https://github.com/cgkineo/babel-plugin-transform-react-templates/issues
- npm.io page: https://npm.io/package/babel-plugin-transform-react-templates

## Dependencies (2)

- [minimatch](https://npm.io/package/minimatch.md) ^3.0.4
- [@babel/helper-plugin-utils](https://npm.io/package/@babel/helper-plugin-utils.md) ^7.10.4

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2026-02-11
- 0.1.0 — 2020-07-05

## README

# babel-plugin-transform-react-templates

> Register react templates with a global function

## Install

Using npm:

```sh
npm install --save-dev babel-plugin-transform-react-templates
```

or using yarn:

```sh
yarn add babel-plugin-transform-react-templates --dev
```

## Usage

Code:

```js
// src/reactTemplateHelpers.js
export default function register(template, component) {
  templates[template] = component;
}

export const templates = {};
```

```js
// src/templates/test.jsx
export default (data) => {
  return <div className="test">
    {data.testText}
  </div>
}
```

```js
// src/main.js
import { templates } from 'src/reactTemplateHelpers';

ReactDOM.render(templates['test']({
  testText: 'testing text'
}), '#app');

```

With options:

```js
plugins: [
  [
    'transform-react-templates',
    {
      includes: [
        // Any jsx file nested inside a templates folder
        '**/templates/**/*.jsx'
      ],
      importRegisterFunctionFromModule: 'src/reactTemplateHelpers.js',
      registerFunctionName: 'register',
      registerTemplateName: (moduleId) => {
        // Use filename as template name
        return path.parse(moduleId).name;
      }
    }
  ]
]
```

Notes:
You must inject the template paths if you want them to appear automatically or include them in a normal import.

---
_Source: https://npm.io/package/babel-plugin-transform-react-templates · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
