vite-plugin-fast-external
Advanced tools
Comparing version 2.1.1 to 2.1.2
{ | ||
"name": "vite-plugin-fast-external", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Without lexical transform, support custom external code.", | ||
"main": "index.js", | ||
"repository": "https://github.com/caoxiemeihao/vite-plugins/tree/main/packages/fast-external", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/caoxiemeihao/vite-plugins.git", | ||
"directory": "packages/fast-external" | ||
}, | ||
"readme": "https://github.com/caoxiemeihao/vite-plugins/tree/main/packages/fast-external#readme", | ||
@@ -12,3 +16,3 @@ "author": "草鞋没号 <308487730@qq.com>", | ||
"devDependencies": { | ||
"vite": "^2.x" | ||
"vite": "^2.x.x" | ||
}, | ||
@@ -15,0 +19,0 @@ "keywords": [ |
@@ -8,3 +8,4 @@ # vite-plugin-fast-external | ||
Without lexical transform, support custom external code | ||
🚀 **High performance** without lexical transform | ||
🌱 Support custom external code | ||
@@ -30,36 +31,54 @@ **English | [简体中文](https://github.com/caoxiemeihao/vite-plugins/blob/main/packages/fast-external/README.zh-CN.md)** | ||
export default defineConfig({ | ||
export default { | ||
plugins: [ | ||
external({ | ||
// Simple example | ||
// By default will generated code -> const Vue = window['Vue']; export { Vue as default } | ||
vue: 'Vue', | ||
}) | ||
] | ||
} | ||
``` | ||
// Support nesting module name | ||
// Support custom external code by function | ||
'@namespace/lib-name': () => ` | ||
const lib = window.LibName; | ||
export default lib; | ||
export const Message = lib.Message | ||
export const Notification = lib.Notification; | ||
`, | ||
#### Customize | ||
// Load a template file and return Promise<string> | ||
externalId: () => require('fs/promises').readFile('path', 'utf-8'), | ||
Support custom external code by function | ||
// Use in Electron | ||
electron: () => `const { ipcRenderer } = require('electron'); export { ipcRenderer }`, | ||
}) | ||
] | ||
```js | ||
external({ | ||
'element-ui': () => ` | ||
const E = window.ELEMENT; | ||
export { E as default }; | ||
export const Loading = E.Loading; | ||
export const Message = E.Message; | ||
export const MessageBox = E.MessageBox; | ||
export const Notification = E.Notification; | ||
`, | ||
// ...other element-ui members | ||
}) | ||
``` | ||
#### Load a file | ||
Support nested module id, support return Promise | ||
```ts | ||
resolve({ | ||
'path/filename': () => require('fs/promises').readFile('path', 'utf-8'), | ||
}) | ||
``` | ||
## API | ||
### external(entries) | ||
external(entries) | ||
**entries** | ||
```ts | ||
Record<string, string | ((id: string) => string | Promise<string>)>; | ||
type entries = Record<string, string | ((id: string) => string | Promise<string>)>; | ||
``` | ||
## How to work | ||
In fact, the plugin will intercept your module import and return the specified code snippet | ||
Let's use `external({ vue: 'Vue' })` as an example, this will get the below code | ||
```js | ||
const M = window['Vue']; export { M as default } | ||
``` |
@@ -8,3 +8,4 @@ # vite-plugin-fast-external | ||
不使用语法转换, 支持自定义 external 代码段 | ||
🚀 **高性能** 不需要语法转换 | ||
🌱 支持自定义 external 代码段 | ||
@@ -33,32 +34,51 @@ **[English](https://github.com/caoxiemeihao/vite-plugins/tree/main/packages/fast-external#readme) | 简体中文** | ||
external({ | ||
// 基本使用 | ||
// 默认会生成 const Vue = window['Vue']; export { Vue as default } | ||
vue: 'Vue', | ||
}) | ||
] | ||
}) | ||
``` | ||
// 支持包命名空间,通过函数可以自定义返回任何代码段 - 但你要知道 vite 开发期只支持 ESM | ||
'@namespace/lib-name': () => ` | ||
const lib = window.LibName; | ||
export default lib; | ||
export const Message = lib.Message | ||
export const Notification = lib.Notification; | ||
`, | ||
#### 自定义 | ||
// 还支持返回 Promise<string> 很容易配合文件、网络等 IO | ||
externalId: () => require('fs/promises').readFile('path', 'utf-8'), | ||
支持通过 function 返回自定义 external 代码 | ||
// 在 Electron 渲染进程中使用 | ||
electron: () => `const { ipcRenderer } = require('electron'); export { ipcRenderer }`, | ||
}) | ||
] | ||
```js | ||
external({ | ||
'element-ui': () => ` | ||
const E = window.ELEMENT; | ||
export { E as default }; | ||
export const Loading = E.Loading; | ||
export const Message = E.Message; | ||
export const MessageBox = E.MessageBox; | ||
export const Notification = E.Notification; | ||
`, | ||
// ...其他 element-ui 导出成员 | ||
}) | ||
``` | ||
#### 加载文件 | ||
支持嵌套模块命名,支持返回 Promise | ||
```ts | ||
resolve({ | ||
'path/filename': () => require('fs/promises').readFile('path', 'utf-8'), | ||
}) | ||
``` | ||
## API | ||
### external(entries) | ||
external(entries) | ||
**entries** | ||
```ts | ||
Record<string, string | ((id: string) => string | Promise<string>)>; | ||
type entries = Record<string, string | ((id: string) => string | Promise<string>)>; | ||
``` | ||
## 工作原理 | ||
实际中,该插件会拦截你的 import 导入,并返回指定的代码段 | ||
Let's use `external({ vue: 'Vue' })` as an example, this will get the code snippet | ||
```js | ||
const M = window['Vue']; export { M as default } | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
6255
83
0
1