vite-plugin-electron-renderer
Advanced tools
Comparing version 0.1.2 to 0.1.3
import { Plugin, UserConfig } from 'vite'; | ||
declare const electronRenderer: VitePluginElectronRenderer; | ||
export default electronRenderer; | ||
export interface Resolve { | ||
@@ -8,3 +11,13 @@ [filename: string]: string | (() => string); | ||
export interface VitePluginElectronRenderer { | ||
(options?: { resolve: Resolve; }): Plugin; | ||
(options?: { | ||
/** | ||
* @example | ||
* { | ||
* resolve: { | ||
* 'electron-store': 'const Store=require("electron-store"); export { Store as default }', | ||
* } | ||
* } | ||
*/ | ||
resolve?: Resolve; | ||
}): Plugin; | ||
} | ||
@@ -34,5 +47,1 @@ | ||
} | ||
// --------- export declare --------- | ||
declare const electronRenderer: VitePluginElectronRenderer; | ||
export default electronRenderer; |
{ | ||
"name": "vite-plugin-electron-renderer", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Use Electron and NodeJs API in Renderer-process", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -38,4 +38,6 @@ [![npm package](https://nodei.co/npm/vite-plugin-electron-renderer.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-electron-renderer) | ||
1. Fist, If you do not configure the following options, the plugin will modify their default values | ||
1. Fist, the plugin will configuration something. | ||
- If you do not configure the following options, the plugin will modify their default values | ||
* `base = './'` | ||
@@ -45,13 +47,27 @@ * `build.assetsDir = ''` | ||
2. The plugin transform 'electron' and NodeJs builtin modules to ESModule format in 'vite serve' phase. | ||
- Add "electron", NodeJs built-in modules and "options.resolve" to "optimizeDeps.exclude" | ||
3. Add 'electron' and NodeJs builtin modules to Rollup 'output.external' option in the 'vite build' phase. | ||
```js | ||
{ | ||
optimizeDeps: { | ||
exclude: [ | ||
'electron', | ||
...'built-in modules', | ||
...Object.keys(options.resolve), | ||
], | ||
}, | ||
} | ||
``` | ||
**Using electron in Renderer-process** | ||
`import { ipcRenderer } from 'electron` | ||
Actually redirect to "[node_modules/vite-plugin-electron-renderer/modules/electron-renderer.js](modules/electron-renderer.js)" through 'resolve.alias' config. | ||
2. The plugin transform "electron" and NodeJs built-in modules to ESModule format in "vite serve" phase. | ||
3. Add "electron" and NodeJs built-in modules to Rollup "output.external" option in the "vite build" phase. | ||
**Using electron in Renderer-process** `import { ipcRenderer } from 'electron` | ||
Actually redirect to "[node_modules/vite-plugin-electron-renderer/modules/electron-renderer.js](modules/electron-renderer.js)" through "resolve.alias". | ||
### Options.resolve | ||
In some cases, you just want 'vite' to load a module like 'node.js'. | ||
In some cases, you just want "vite" to load a module like NodeJs. | ||
You can custom-resolve the module **eg:** | ||
@@ -58,0 +74,0 @@ |
@@ -37,4 +37,6 @@ [![npm package](https://nodei.co/npm/vite-plugin-electron-renderer.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-electron-renderer) | ||
1. 首先,在你没主动配置过下列配置时,插件会修改它们的默认值 | ||
1. 首先,插件会修改一些配置 | ||
- 在你没主动配置过下列配置时,插件会修改它们的默认值 | ||
* `base = './'` | ||
@@ -44,14 +46,16 @@ * `build.assetsDir = ''` | ||
- 将 'electron',NodeJs 内置模块和 `options.resolve` 插入到 "optimizeDeps.exclude" 中 | ||
2. 开发阶段(`vite serve`) 将 Electron 和 NodeJs 内置模块转换成 ESModule 格式 | ||
3. 打包阶段(`vite build`) 将 'electron' 和 NodeJs 内置模块插入到 Rollup 的 'output.external' 中 | ||
3. 打包阶段(`vite build`) 将 "electron" 和 NodeJs 内置模块插入到 Rollup 的 "output.external" 中 | ||
**Using electron in Renderer-process** | ||
`import { ipcRenderer } from 'electron` | ||
实际上通过 `resolve.alias` 重定向到 "[node_modules/vite-plugin-electron-renderer/modules/electron-renderer.js](modules/electron-renderer.js)" | ||
**在想染进程中使用 electron** `import { ipcRenderer } from 'electron` | ||
实际上通过 "resolve.alias" 重定向到 "[node_modules/vite-plugin-electron-renderer/modules/electron-renderer.js](modules/electron-renderer.js)" | ||
### Options.resolve | ||
很多时候, 你只想在 Vite 中用 NodeJs 的方式加载模块 | ||
通过 'resolve' 配置实现 **例如:** | ||
通过 "resolve" 配置实现 **例如:** | ||
@@ -58,0 +62,0 @@ **vite.config.ts** |
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
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
14295
227
102