docs: 🚨 Node.js ESM packages

This commit is contained in:
草鞋没号 2022-07-11 08:43:06 +08:00
parent 817498e2d9
commit 7380421914
2 changed files with 10 additions and 29 deletions

View File

@ -12,8 +12,8 @@ English | [简体中文](README.zh-CN.md)
📦 Out of the box
🎯 Based on the official [react-ts](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) template, less invasive
🌱 Simple directory structurereal flexible
💪 Support Use Electron、Node.js API and in Electron-Renderer
🌱 Extensible, really simple directory structure
💪 Support using Node.js API in Electron-Renderer
🔩 Support C/C++ native addons
🖥 It's easy to implement multiple windows
@ -44,7 +44,7 @@ npm create electron-vite
│ └── uninstallerIcon.ico Icon for the application uninstaller
├── release Generated after production build, contains executables
│ └──{version}
│ └── {version}
│ ├── {os}-unpacked Contains unpacked application executable
│ └── Setup.{ext} Installer for the application
@ -64,21 +64,11 @@ npm create electron-vite
See more 👉 [dependencies vs devDependencies](https://github.com/electron-vite/vite-plugin-electron-renderer#dependencies-vs-devdependencies)
## 🚨 ESM packages
## 🚨 Node.js ESM packages
**e.g.** `node-fetch` `execa` `got` ...others
**e.g.** `node-fetch` `execa` `got` ...
1. `npm i vite-plugin-esmodule -D`
2. Configure in vite.config.ts
```ts
import esmodule from 'vite-plugin-esmodule'
export default {
plugins: [
esmodule(['got', 'execa', 'node-fetch']),
],
}
```
[👉 Using Node.js ESM packages in Electron-Renderer](https://github.com/electron-vite/vite-plugin-electron-renderer#-nodejs-esm-packages)
<!--
- First, you need to know if your dependencies are needed after the application is packaged.

View File

@ -44,7 +44,7 @@ npm create electron-vite
│ └── uninstallerIcon.ico 卸载图标
├── release 构建后生成程序目录
│ └──{version}
│ └── {version}
│ ├── {os}-unpacked 未打包的程序(绿色运行版)
│ └── Setup.{ext} 应用安装文件
@ -64,21 +64,12 @@ npm create electron-vite
看看这 👉 [dependencies vs devDependencies](https://github.com/electron-vite/vite-plugin-electron-renderer#dependencies-vs-devdependencies)
## 🚨 ESM packages
**e.g.** `node-fetch` `execa` `got` ...others
## 🚨 Node.js ESM packages
1. `npm i vite-plugin-esmodule -D`
2. Configure in vite.config.ts
**e.g.** `node-fetch` `execa` `got` ...
```ts
import esmodule from 'vite-plugin-esmodule'
export default {
plugins: [
esmodule(['got', 'execa', 'node-fetch']),
],
}
```
[👉 在 Electron-Renderer 中使用 Node.js ESM 包](https://github.com/electron-vite/vite-plugin-electron-renderer#-nodejs-esm-packages)
<!--
&emsp;&emsp;对待 **Electron-Main、Preload-Script** 时 vite 会以 lib 形式打包 commonjs 格式代码;