vite-plugin-resolve
Advanced tools
Comparing version 2.0.9 to 2.1.0
{ | ||
"name": "vite-plugin-resolve", | ||
"version": "2.0.9", | ||
"version": "2.1.0", | ||
"description": "Custom resolve module content.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
110
README.md
@@ -12,2 +12,4 @@ # vite-plugin-resolve | ||
🤔 You can think of this as the implementation of the official tutorial 👉 [Virtual Modules Convention](https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention) | ||
📦 **Out of the box**, builtin Vue, React, Antd, Element and others | ||
🌱 Support custom code snippets | ||
✅ Browser, Node.js, Electron | ||
@@ -31,3 +33,17 @@ | ||
resolve({ | ||
vue: `const vue = window.Vue; export { vue as default }`, | ||
// Browser | ||
vue: ` | ||
const vue = window.Vue; | ||
export { vue as default } | ||
export const version = vue.version; | ||
`, | ||
// Node.js, Electron | ||
electron: ` | ||
const { ipcRenderer, shell } = require('electron'); | ||
export { | ||
ipcRenderer, | ||
shell, | ||
} | ||
// ...others | ||
`, | ||
}), | ||
@@ -42,7 +58,5 @@ ] | ||
import Vue from 'vue' | ||
import { ipcRenderer, shell } from 'electron' | ||
``` | ||
This like Vite external plugin | ||
You you can see more about external 👉 [vite-plugin-fast-external](https://github.com/caoxiemeihao/vite-plugins/tree/main/packages/fast-external) | ||
**Load a file** | ||
@@ -60,24 +74,2 @@ | ||
**Electron** | ||
Resolve Electron Renderer-process | ||
```ts | ||
resolve({ | ||
electron: ` | ||
const electron = require("electron"); | ||
export { electron as default } | ||
const export shell = electron.shell; | ||
const export ipcRenderer = electron.ipcRenderer; | ||
// ...others | ||
`, | ||
}) | ||
``` | ||
In you App(Renderer-process) | ||
```ts | ||
import { shell, ipcRenderer } from 'electron' | ||
``` | ||
## API | ||
@@ -99,2 +91,68 @@ | ||
## Use builtin modules | ||
This like Vite external plugin | ||
```js | ||
import resolve from 'vite-plugin-resolve' | ||
import { | ||
antd_vue, | ||
antd, | ||
element_plus, | ||
element_ui, | ||
pinia, | ||
react_dom, | ||
react_router_dom, | ||
react_router, | ||
react, | ||
redux, | ||
vue_composition_api, | ||
vue_router, | ||
vue, | ||
vuex, | ||
} from 'vite-plugin-resolve/presets' | ||
export default { | ||
plugins: [ | ||
resolve({ | ||
vue: vue.v3, | ||
}), | ||
] | ||
} | ||
// Use in your app | ||
import { h, ref, reactive, watch } from 'vue' | ||
``` | ||
**Advance**, you can use `lib2esm()` to customize some things | ||
```js | ||
import resolve from 'vite-plugin-resolve' | ||
import { lib2esm } from 'vite-plugin-resolve/presets' | ||
export default { | ||
plugins: [ | ||
resolve({ | ||
// Let's use lodash as an example | ||
lodash: lib2esm( | ||
// lodash iife name | ||
'_', | ||
// export memebers | ||
[ | ||
'chunk', | ||
'curry', | ||
'debounce', | ||
'throttle', | ||
], | ||
), | ||
}), | ||
] | ||
} | ||
// Use in your app | ||
import { chunk, curry, debounce, throttle } from 'lodash' | ||
``` | ||
**Use in Electron** 👉 [electron-vite-vue](https://github.com/electron-vite/electron-vite-vue/blob/main/packages/renderer/vite.config.ts) | ||
## What's different from the official Demo? | ||
@@ -101,0 +159,0 @@ |
@@ -12,2 +12,4 @@ # vite-plugin-resolve | ||
🤔 你可以认为它是官方教程的一个实现 👉 [Virtual Modules Convention](https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention) | ||
📦 **开箱即用**, 内置 Vue, React, Antd, Element 等等 | ||
🌱 支持自定义 external 代码段 | ||
✅ Browser, Node.js, Electron | ||
@@ -31,3 +33,17 @@ | ||
resolve({ | ||
vue: `const vue = window.Vue; export { vue as default }`, | ||
// Browser | ||
vue: ` | ||
const vue = window.Vue; | ||
export { vue as default } | ||
export const version = vue.version; | ||
`, | ||
// Node.js, Electron | ||
electron: ` | ||
const { ipcRenderer, shell } = require('electron'); | ||
export { | ||
ipcRenderer, | ||
shell, | ||
} | ||
// ...others | ||
`, | ||
}), | ||
@@ -42,9 +58,7 @@ ] | ||
import Vue from 'vue' | ||
import { ipcRenderer, shell } from 'electron' | ||
``` | ||
这个场景就是 external | ||
你可以看看关于 external 👉 [vite-plugin-fast-external](https://github.com/caoxiemeihao/vite-plugins/tree/main/packages/fast-external) | ||
**加载文件** | ||
#### 加载文件 | ||
支持嵌套模块命名,支持返回 Promise | ||
@@ -60,24 +74,2 @@ | ||
#### Electron | ||
加载 Electron 渲染进程 | ||
```ts | ||
resolve({ | ||
electron: ` | ||
const electron = require("electron"); | ||
export { electron as default } | ||
const export shell = electron.shell; | ||
const export ipcRenderer = electron.ipcRenderer; | ||
// ...其他成员 | ||
`, | ||
}) | ||
``` | ||
在渲染进程中使用 | ||
```ts | ||
import { shell, ipcRenderer } from 'electron' | ||
``` | ||
## API | ||
@@ -99,2 +91,68 @@ | ||
## 使用内置模块 | ||
这个场景就是 Vite external plugin | ||
```js | ||
import resolve from 'vite-plugin-resolve' | ||
import { | ||
antd_vue, | ||
antd, | ||
element_plus, | ||
element_ui, | ||
pinia, | ||
react_dom, | ||
react_router_dom, | ||
react_router, | ||
react, | ||
redux, | ||
vue_composition_api, | ||
vue_router, | ||
vue, | ||
vuex, | ||
} from 'vite-plugin-resolve/presets' | ||
export default { | ||
plugins: [ | ||
resolve({ | ||
vue: vue.v3, | ||
}), | ||
] | ||
} | ||
// 使用 | ||
import { h, ref, reactive, watch } from 'vue' | ||
``` | ||
**Advance**, you can use `lib2esm()` to customize some things | ||
```js | ||
import resolve from 'vite-plugin-resolve' | ||
import { lib2esm } from 'vite-plugin-resolve/presets' | ||
export default { | ||
plugins: [ | ||
resolve({ | ||
// 用 lodash 举个 🌰 | ||
lodash: lib2esm( | ||
// lodash 全局名称 | ||
'_', | ||
// export memebers | ||
[ | ||
'chunk', | ||
'curry', | ||
'debounce', | ||
'throttle', | ||
], | ||
), | ||
}), | ||
] | ||
} | ||
// 使用 | ||
import { chunk, curry, debounce, throttle } from 'lodash' | ||
``` | ||
**在 Electron 中使用** 👉 [electron-vite-vue](https://github.com/electron-vite/electron-vite-vue/blob/main/packages/renderer/vite.config.ts) | ||
## 这与官方的 Demo 有何异同? | ||
@@ -101,0 +159,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
43423
28
1839
159
1