# @cocos/babel-plugin-dynamic-import-vars

> Babel plugin to route your dynamic import.

Latest version **1.0.2** (published 2020-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cocos/babel-plugin-dynamic-import-vars
pnpm add @cocos/babel-plugin-dynamic-import-vars
yarn add @cocos/babel-plugin-dynamic-import-vars
bun add @cocos/babel-plugin-dynamic-import-vars
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-10-30 |
| First published | 2020-10-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | cocos |

## Links

- npm: https://www.npmjs.com/package/@cocos/babel-plugin-dynamic-import-vars
- Homepage: http://www.cocos.com
- npm.io page: https://npm.io/package/@cocos/babel-plugin-dynamic-import-vars

## Dependencies (1)

- [globby](https://npm.io/package/globby.md) ^11.0.1

## Recent versions

- 1.0.2 (latest) — 2020-10-30
- 1.0.1 — 2020-10-30

## README

# @cocos/babel-plugin-dynamic-import-vars

Inspired from [@rollup/plugin-dynamic-import-vars](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars).

This plugin transforms for example:

```js
import(`./${lang}.js`)
```

into

```js
((specifier) => {
    switch (specifier) {
        case './zh-cn.js': return import('./zh-cn.js');
        case './en-us.js': return import('./en-us.js');
        default: return import(specifier);
    }
})(`./${lang}.js`)
```

given `'./${lang}.js'` can be statically resolved as `'./zh-cn.js'`, `'./en-us.js'` etc.

# Rules

Similar with `@rollup/plugin-dynamic-import-vars` except that:

- If none of the preset specifiers matches, the code won't throw but still fallback to run.

- Supplied an options to resolve `.js` to others for example `.ts`.

---
_Source: https://npm.io/package/@cocos/babel-plugin-dynamic-import-vars · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
