Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/woai3c/rollup-plugin-import-to-const
将 import 导入变量替换为 const 命名变量 的 rollup 插件
https://github.com/woai3c/rollup-plugin-import-to-const
Last synced: 2 months ago
JSON representation
将 import 导入变量替换为 const 命名变量 的 rollup 插件
- Host: GitHub
- URL: https://github.com/woai3c/rollup-plugin-import-to-const
- Owner: woai3c
- License: mit
- Created: 2023-07-22T05:07:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-05T14:43:25.000Z (11 months ago)
- Last Synced: 2024-10-12T20:38:44.295Z (3 months ago)
- Language: TypeScript
- Size: 45.9 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rollup-plugin-import-to-const
将 import 导入变量替换为 const 命名变量的 rollup 插件,主要用于在前端项目中加载 esm 格式的远程组件。较常见的使用场景可能是低代码平台加载远程组件。
```js
import { computed } from 'vue'
↓
const { computed } = Vue
```## 使用
安装
```sh
npm i -D rollup-plugin-import-to-const
# or
pnpm i -D rollup-plugin-import-to-const
```引入
```js
import importToConst from 'rollup-plugin-import-to-const'const config = {
external: [
'vue',
'element-plus',
],
output: {
globals: {
vue: 'Vue', // import { computed } from 'vue' => const { computed } = Vue
'element-plus': 'ElementPlus', // import { ElRate } from 'element-plus' => const { ElRate } = ElementPlus
},
},
plugins: [
// other plugins...
importToConst(),
]
}
```插件会根据 `output.globals` 上的变量映射规则去替换代码中的变量。