Socket
Socket
Sign inDemoInstall

vite-plugin-fast-external

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-fast-external - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

10

package.json
{
"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 }
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc