docs: 🚨 Node.js ESM packages
This commit is contained in:
		
							parent
							
								
									817498e2d9
								
							
						
					
					
						commit
						7380421914
					
				
							
								
								
									
										22
									
								
								README.md
								
								
								
								
							
							
						
						
									
										22
									
								
								README.md
								
								
								
								
							| 
						 | 
					@ -12,8 +12,8 @@ English | [简体中文](README.zh-CN.md)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
📦 Out of the box  
 | 
					📦 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  
 | 
					🎯 Based on the official [react-ts](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) template, less invasive  
 | 
				
			||||||
🌱 Simple directory structure,real flexible  
 | 
					🌱 Extensible, really simple directory structure  
 | 
				
			||||||
💪 Support Use Electron、Node.js API and in Electron-Renderer  
 | 
					💪 Support using Node.js API in Electron-Renderer  
 | 
				
			||||||
🔩 Support C/C++ native addons  
 | 
					🔩 Support C/C++ native addons  
 | 
				
			||||||
🖥 It's easy to implement multiple windows  
 | 
					🖥 It's easy to implement multiple windows  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,7 @@ npm create electron-vite
 | 
				
			||||||
│       └── uninstallerIcon.ico   Icon for the application uninstaller
 | 
					│       └── uninstallerIcon.ico   Icon for the application uninstaller
 | 
				
			||||||
│
 | 
					│
 | 
				
			||||||
├── release                   Generated after production build, contains executables
 | 
					├── release                   Generated after production build, contains executables
 | 
				
			||||||
│   └──{version}
 | 
					│   └── {version}
 | 
				
			||||||
│       ├── {os}-unpacked     Contains unpacked application executable
 | 
					│       ├── {os}-unpacked     Contains unpacked application executable
 | 
				
			||||||
│       └── Setup.{ext}       Installer for the application
 | 
					│       └── 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)
 | 
					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`
 | 
					[👉 Using Node.js ESM packages in Electron-Renderer](https://github.com/electron-vite/vite-plugin-electron-renderer#-nodejs-esm-packages)
 | 
				
			||||||
2. Configure in vite.config.ts
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```ts
 | 
					 | 
				
			||||||
import esmodule from 'vite-plugin-esmodule'
 | 
					 | 
				
			||||||
export default {
 | 
					 | 
				
			||||||
  plugins: [
 | 
					 | 
				
			||||||
    esmodule(['got', 'execa', 'node-fetch']),
 | 
					 | 
				
			||||||
  ],
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
<!--
 | 
					<!--
 | 
				
			||||||
- First, you need to know if your dependencies are needed after the application is packaged.
 | 
					- First, you need to know if your dependencies are needed after the application is packaged.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,7 @@ npm create electron-vite
 | 
				
			||||||
│       └── uninstallerIcon.ico   卸载图标
 | 
					│       └── uninstallerIcon.ico   卸载图标
 | 
				
			||||||
│
 | 
					│
 | 
				
			||||||
├── release                   构建后生成程序目录
 | 
					├── release                   构建后生成程序目录
 | 
				
			||||||
│   └──{version}
 | 
					│   └── {version}
 | 
				
			||||||
│       ├── {os}-unpacked     未打包的程序(绿色运行版)
 | 
					│       ├── {os}-unpacked     未打包的程序(绿色运行版)
 | 
				
			||||||
│       └── Setup.{ext}       应用安装文件
 | 
					│       └── 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)
 | 
					看看这 👉 [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`
 | 
					**e.g.** `node-fetch` `execa` `got` ...
 | 
				
			||||||
2. Configure in vite.config.ts
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
```ts
 | 
					[👉 在 Electron-Renderer 中使用 Node.js ESM 包](https://github.com/electron-vite/vite-plugin-electron-renderer#-nodejs-esm-packages)
 | 
				
			||||||
import esmodule from 'vite-plugin-esmodule'
 | 
					 | 
				
			||||||
export default {
 | 
					 | 
				
			||||||
  plugins: [
 | 
					 | 
				
			||||||
    esmodule(['got', 'execa', 'node-fetch']),
 | 
					 | 
				
			||||||
  ],
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
<!--
 | 
					<!--
 | 
				
			||||||
  对待 **Electron-Main、Preload-Script** 时 vite 会以 lib 形式打包 commonjs 格式代码;
 | 
					  对待 **Electron-Main、Preload-Script** 时 vite 会以 lib 形式打包 commonjs 格式代码;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue