feat: use Node.js in Renderer process
This commit is contained in:
		
							parent
							
								
									e2cedd24cf
								
							
						
					
					
						commit
						0566305c79
					
				
							
								
								
									
										11
									
								
								README.md
								
								
								
								
							
							
						
						
									
										11
									
								
								README.md
								
								
								
								
							| 
						 | 
					@ -65,9 +65,14 @@ To get started, remove the option as shown below. This will [modify the Vite con
 | 
				
			||||||
```diff
 | 
					```diff
 | 
				
			||||||
# vite.config.ts
 | 
					# vite.config.ts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
electron({
 | 
					export default {
 | 
				
			||||||
- renderer: {}
 | 
					  plugins: [
 | 
				
			||||||
})
 | 
					-   // Use Node.js API in the Renderer-process
 | 
				
			||||||
 | 
					-   renderer({
 | 
				
			||||||
 | 
					-     nodeIntegration: true,
 | 
				
			||||||
 | 
					-   }),
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## ❔ FAQ
 | 
					## ❔ FAQ
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,8 @@
 | 
				
			||||||
    "sass": "^1.55.0",
 | 
					    "sass": "^1.55.0",
 | 
				
			||||||
    "typescript": "^4.8.4",
 | 
					    "typescript": "^4.8.4",
 | 
				
			||||||
    "vite": "^3.1.4",
 | 
					    "vite": "^3.1.4",
 | 
				
			||||||
    "vite-electron-plugin": "^0.4.6"
 | 
					    "vite-electron-plugin": "^0.4.6",
 | 
				
			||||||
 | 
					    "vite-plugin-electron-renderer": "^0.10.1"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "debug": {
 | 
					  "debug": {
 | 
				
			||||||
    "env": {
 | 
					    "env": {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								src/main.tsx
								
								
								
								
							
							
						
						
									
										10
									
								
								src/main.tsx
								
								
								
								
							| 
						 | 
					@ -1,17 +1,9 @@
 | 
				
			||||||
import React from 'react'
 | 
					import React from 'react'
 | 
				
			||||||
import ReactDOM from 'react-dom/client'
 | 
					import ReactDOM from 'react-dom/client'
 | 
				
			||||||
import App from './App'
 | 
					import App from './App'
 | 
				
			||||||
 | 
					import './samples/node-api'
 | 
				
			||||||
import 'styles/index.css'
 | 
					import 'styles/index.css'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * If you enables use of Node.js API in the Renderer-process
 | 
					 | 
				
			||||||
 * ```
 | 
					 | 
				
			||||||
 * npm i -D vite-plugin-electron-renderer
 | 
					 | 
				
			||||||
 * ```
 | 
					 | 
				
			||||||
 * @see - https://github.com/electron-vite/vite-plugin-electron/tree/main/packages/electron-renderer#electron-renderervite-serve
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
// import './samples/node-api'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ReactDOM.createRoot(document.getElementById('root')!).render(
 | 
					ReactDOM.createRoot(document.getElementById('root')!).render(
 | 
				
			||||||
  <React.StrictMode>
 | 
					  <React.StrictMode>
 | 
				
			||||||
    <App />
 | 
					    <App />
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import { defineConfig } from 'vite'
 | 
				
			||||||
import react from '@vitejs/plugin-react'
 | 
					import react from '@vitejs/plugin-react'
 | 
				
			||||||
import electron from 'vite-electron-plugin'
 | 
					import electron from 'vite-electron-plugin'
 | 
				
			||||||
import { customStart } from 'vite-electron-plugin/plugin'
 | 
					import { customStart } from 'vite-electron-plugin/plugin'
 | 
				
			||||||
 | 
					import renderer from 'vite-plugin-electron-renderer'
 | 
				
			||||||
import pkg from './package.json'
 | 
					import pkg from './package.json'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
rmSync(path.join(__dirname, 'dist-electron'), { recursive: true, force: true })
 | 
					rmSync(path.join(__dirname, 'dist-electron'), { recursive: true, force: true })
 | 
				
			||||||
| 
						 | 
					@ -31,6 +32,9 @@ export default defineConfig({
 | 
				
			||||||
        ? [customStart(debounce(() => console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')))]
 | 
					        ? [customStart(debounce(() => console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')))]
 | 
				
			||||||
        : undefined,
 | 
					        : undefined,
 | 
				
			||||||
    }),
 | 
					    }),
 | 
				
			||||||
 | 
					    renderer({
 | 
				
			||||||
 | 
					      nodeIntegration: true,
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
  ],
 | 
					  ],
 | 
				
			||||||
  server: process.env.VSCODE_DEBUG ? (() => {
 | 
					  server: process.env.VSCODE_DEBUG ? (() => {
 | 
				
			||||||
    const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
 | 
					    const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue