File size: 657 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Babel plugin optimize i18n

Babel plugin that transforms this:

```js
import { __, _x } from '@wordpress/i18n';

__( 'Hello' );
_x( 'World' );
```

to this:

```js
import { __ as alias__, _x as alias_x } from '@wordpress/i18n';
const __ = alias__;
const _x = alias_x;

__( 'Hello' );
_x( 'World' );
```

Inspired by [babel-plugin-optimize-react](https://www.npmjs.com/package/babel-plugin-optimize-react) that does similar transforms for React imports.

The transform ensures that the `__('Hello')` syntax remains intact in the output bundle (and even after minification if Terser uses the `mangle.reserved` option) and can be extracted by WP i18n tools.