์๋ ํ์ธ์
์ ๋ ๋ค๋ฅธ ํ๋ฌ๊ทธ์ธ ์ค์์ React.js ๋ฐ babelify์ ํจ๊ป Electron์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค(ํ๋จ ๋ชฉ๋ก).
์๋ฅผ ๋ค์ด ์ ์์ BrowserWindow
์ ์ก์ธ์คํ๊ธฐ ์ํด require('electron')
๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ๋ฉด ์ฝ์์ ๋ค์ ์ค๋ฅ๊ฐ ํ์๋ฉ๋๋ค.
index.js:4 Uncaught TypeError: fs.readFileSync is not a function
๊ทธ๋ฌ๋ main.js์์ const electron = require('electron');
๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๊ทธ๋งํ ๊ฐ์น๊ฐ ์๊ธฐ ๋๋ฌธ์ watchify๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ ๊ฒ์ js ๋ฒ๋ค๋ก ๋ฌถ์ต๋๋ค.
๋ค์์ ๋ด package.json์ ์ ์ฒด ์ข ์์ฑ ๋ชฉ๋ก์ ๋๋ค.
"devDependencies": {
"axios": "^0.9.1",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babelify": "^7.2.0",
"classnames": "^2.2.3",
"electron": "^1.3.5",
"electron-reload": "^0.2.0",
"jquery": "^2.2.3",
"react": "^0.14.8",
"react-autocomplete": "^1.0.0-rc2",
"react-dom": "^0.14.7",
"react-sound": "^0.4.0",
"soundmanager2": "^2.97.20150601-a"
},
index.js:4 ์กํ์ง ์์ TypeError: fs.readFileSync๋ ํจ์๊ฐ ์๋๋๋ค.
์ฌ๊ธฐ์ index.js
์ 4ํ์ ํฌํจํ ์ ์์ต๋๊น? ์๋๋ฉด ์ ์ฒด ์คํ ์ถ์ ?
๋๋ ๊ทธ๊ฒ์ด ํ๋ก์ ํธ์ ๋ ธ๋ ๋ชจ๋์ ์์นํ ์ ์์ index.js๋ฅผ ์ฐธ์กฐํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ์ด ํ์ผ์ ๋ด์ฉ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
var fs = require('fs')
var path = require('path')
module.exports = path.join(__dirname, fs.readFileSync(path.join(__dirname, 'path.txt'), 'utf-8'))
์ ์ฒด ์คํ ์ถ์ ์ React.js์์ ์ถฉ๋์ ์์ํฉ๋๋ค.
๊ฐ๋ฐ์ ๋๊ตฌ์ ์ฝ์ ํญ์์ require('fs').readFileSync
๋ฅผ ์คํํ๋ฉด ์ด๋ป๊ฒ ๋ฉ๋๊น?
electron-prebuilt
๋
ธ๋ ๋ชจ๋(๋ถ์ฌ๋ฃ์ ํ์ผ)์ด ๋ด์ฅ๋ electron
require๋ฅผ ๋์ ์ฌ์ฉํด์ผ ํ๊ธฐ ๋๋ฌธ์ ์ํ์ง ์๋ ํจํค์ง ์ฑ์์ ๋๋๋ ๊ฒ ๊ฐ์ต๋๋ค.
@nukeop ์ฑ์ ์ด๋ป๊ฒ ๋ฐ์นญํ๊ณ ์๋์? `์์ ์คํฌ๋ฆฝํธ๋ ๋ค์๊ณผ ๊ฐ์์ผ ํฉ๋๋ค.
"scripts": {
"start": "electron ."
}
๋
ธ๋๋ฅผ ์ฌ์ฉํ์ฌ main.js
๋ฅผ ์คํํ๋ ค๊ณ ์๋ํ๊ณ ์๋ค๋ ๋๋์ด ๋ญ๋๋ค.
node main.js
์๋ํ์ง ์๋ ๊ฒ
dev ๋๊ตฌ์ ์ฝ์ ํญ์์ require('fs').readFileSync๋ฅผ ์คํํ๋ฉด ์ด๋ป๊ฒ ๋ฉ๋๊น?
์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ ์งํ์ ์ฝ์์์ require('fs').existsSync
๋ฅผ ์คํํ์ฌ ํจ์ ์ ์๋ฅผ ์ธ์ํ ์ ์์ต๋๋ค. ์ค๋ฅ ์ ์๋ ์๋ํฉ๋๋ค.
์ ์๊ฐ ๋ฏธ๋ฆฌ ๋น๋๋ ๋ ธ๋ ๋ชจ๋(๋ถ์ฌ ๋ฃ์ ํ์ผ)์ด ๋ด์ฅ ์ ์ ์๊ตฌ๋ฅผ ๋์ ์ฌ์ฉํด์ผ ํ๊ธฐ ๋๋ฌธ์ ์ํ์ง ์๋ ํจํค์ง ์ฑ์์ ๋๋๋ ๊ฒ์ฒ๋ผ ๋ณด์ ๋๋ค.
๊ณ์ํด์ ํจํค์ง๋ฅผ ์ ๋ฐ์ดํธํ๋ ๊ฐ๋ฐ ์ค์ธ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํ ์ค์ธ watchify ์ธ์คํด์ค๊ฐ ์์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ด package.json์ ์คํฌ๋ฆฝํธ ์น์ ์์ ์ ์ํ์ต๋๋ค.
"watch": "watchify app/app.js -t babelify -o public/js/bundle.js --debug --verbose"
electron-prebuilt
๋ฒ๋ค์ ํผํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์กฐ์ธ์ด ์์ต๋๊น?
@nukeop Electron ์ง์์ ๋ด๋ถ์ ์ผ๋ก ํ์ํ๋ฏ๋ก browserify๋ฅผ ์ฌ์ฉํ ํ์๊ฐ ์์ต๋๋ค.
๋ด๊ฐ ์๋ ํ Browserify๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด "์ ์"๋ฅผ ์ ์ธํด์ผ ํฉ๋๋ค.
ํฅ๋ฏธ๋กญ์ต๋๋ค. watchify/browserify๊ฐ ์ด๊ฒ์ ๋ง์น ์ ์์ต๋๊น? ์ง๊ธ๊น์ง ์ ์์ ์ผ๋ก ์๋ํ์ต๋๋ค.
์ง๊ธ์ ๊ทธ๊ฒ ์์ด ํ๋ก๊ทธ๋จ์ ์คํํ๋ ๋ฐฉ๋ฒ์ ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
๋ง ๊ทธ๋๋ก ๊ทธ๋ฅ ์คํ
electron .
Electron์ ๋ด๋ถ์ ์ผ๋ก ์ ์ฒด ๋ ธ๋ ํ๊ฒฝ์ ๊ฐ์ง๊ณ ์๊ธฐ ๋๋ฌธ์ ๊ธฐ๋ณธ ์ฑ ํด๋์์ ์๋ฌด ๊ฒ๋ ๋ฒ๋คํ ํ์๊ฐ ์์ต๋๋ค.
_Browserify ๋ฌธ์ ์ด๋ฏ๋ก ์ข ๋ฃํ๊ฒ ์ต๋๋ค_
๊ทธ๊ฒ์ด ๋ด๊ฐ ์ค๊ณง ํด์จ ์ผ์ด๋ฉฐ, ํ๋ก๊ทธ๋จ์ ๋จ์ผ .js ํ์ผ๋ก ๋ฌถ๋ ๊ฒ์ ๋๋ค. ์ด ํ์ผ์ ๋ค์์ด ํฌํจ๋ ๊ฐ๋จํ html ํ์ผ์ ํฌํจ๋์ด ์์ต๋๋ค.
<script src="public/js/bundle.js">
</script>
๊ทธ๋ฆฌ๊ณ ๋ด๊ฐ require๋ฅผ ์ฌ์ฉํ ๋๋ฅผ ์ ์ธํ๊ณ ๋ชจ๋ ๊ฒ์ด ์๋ํฉ๋๋ค. ์ด๊ฒ์ ๋ ๋ชจ๋ ๊ฐ์ ์ํธ ์์ฉ ๋ฌธ์ ์ ๋๋ค.
์ ์ฒด ํ๋ก๊ทธ๋จ์ ๋ฒ๋ค๋ก ๋ฌถ์ง ์์ผ๋ฉด main.js๊ฐ ์ ์๋ง ์์ํ๊ณ ๋ฒ๋ค์ ํฌํจํ๋ html ํ์ผ์ ๋ก๋ํ๋ฏ๋ก ์ฝ๊ฒ ์คํํ ์ ์์ต๋๋ค.
@nukeop Electron ๋ด๋ถ์ ๋ ๋๋ฌ ํ๋ก์ธ์ค๋ ์ ์ฒด ๋ ธ๋/commonjs ํ๊ฒฝ์๋ ์ก์ธ์คํ ์ ์์ผ๋ฏ๋ก ๋ฒ๋ค๋ก ์ ๊ณตํ ํ์๊ฐ ์์ต๋๋ค.
์ ์ฒด ํ๋ก๊ทธ๋จ์ ๋ฒ๋ค๋ก ๋ฌถ์ง ์์ผ๋ฉด main.js๊ฐ ์ ์๋ง ์์ํ๊ณ ๋ฒ๋ค์ ํฌํจํ๋ html ํ์ผ์ ๋ก๋ํ๋ฏ๋ก ์ฝ๊ฒ ์คํํ ์ ์์ต๋๋ค.
HTML ํ์ผ์ ๋ก๋ํ๋ ๋ชจ๋ ์คํฌ๋ฆฝํธ์๋ ์์ ํ commonjs ํ๊ฒฝ์ด ์์ผ๋ฏ๋ก require
๋ฅผ ์ฌ์ฉํ์ฌ ๋ธ๋ผ์ฐ์ ํํ์ง ์๊ณ ๋ ์ถ๊ฐ ํ์ผ์ ๋ก๋ํ ์ ์์ต๋๋ค.
๋ฏธ๋์ ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ณ ์ด ์ค๋ ๋๋ฅผ ์ฝ๋ ์ฌ๋์๊ฒ๋ require ๋์ window.require
๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ ์์ browserify์ require
ํจ์ ๊ฐ์ ์ถฉ๋์ ํผํ ์ ์๋ ํ ๊ฐ์ง ๊ฐ๋ฅ์ฑ์
๋๋ค.
FWIW, ๋๋ ๋ธ๋ผ์ฐ์ ํ ๋์ ๋ฐฑ์๋์์ ์นํฉ์ ์ฌ์ฉํ๋ create-react-app๊ณผ ํจ๊ป ๋ ๋๋ฌ ํ๋ก์ธ์ค์์ ์ ์๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ์๋ํ๋ ๊ฒ๊ณผ ๋์ผํ ๋ฌธ์ ์ ๋ถ๋ช์ณค์ต๋๋ค. window.require
์ด์ ๋ ํ์คํ์ง ์์ง๋ง ์ ์๊ฒ๋ ํด๊ฒฐ๋๋ ๊ฒ ๊ฐ์ต๋๋ค.
ํธ์ง : ์ด์ ๋ฅผ ์์ ๋์ต๋๋ค :-) webpack์์ ์ปดํ์ผํ๋ ๋์ ์ฌ์ฉํ๋ nodejs ํ๊ฒฝ์ด ์๋๋ผ ๋ฐํ์์ ์ ๊ณต๋๋ nodejs ํ๊ฒฝ์์ ๋ฐํ์ ์ค์ require
electron
๋ฅผ ์ํ์ต๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ์ ์ญ์ window
์ ๋ฐ์ธ๋ฉ๋๊ณ webpack ์ปดํ์ผ์ window
์ ์ญ์ ๋ฌด์ํ๋ฏ๋ก window.require
๊ฐ ์๋ํฉ๋๋ค.
webpack์ ์ ์ญ ์ด๋ฆ์ ๋ฌด์ํ๋๋ก ์ง์ํ๋ ๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ JS ํ์ผ์์ /*global Android*/
์ ๊ฐ์ ์ฃผ์์ ์ฌ์ฉํ๋ ๊ฒ์
๋๋ค. Android WebView์์ CRA ๋น๋ ์ฑ์ ์ฌ์ฉํ๋ ๋ค๋ฅธ ํ๋ก์ ํธ์์๋ Webview์์ ์ ๊ณตํ๋ JavaScript ์ธํฐํ์ด์ค๋ฅผ ํตํด JS์ ๋
ธ์ถ๋ Java ๊ฐ์ฒด์ ์ก์ธ์คํ๊ธฐ ์ํด ์์ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ์ต๋๋ค.
@nukeop - ๋ง์ง๋ง ๊ฒ์๋ฌผ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ๋ง์ ๋์์ด ๋์์ต๋๋ค. window.require
๋๋ฅผ ์ํด ์ผํ์ต๋๋ค.
๋ค, ๋ฐ์ ์ฑ ์์ฑ/์นํฉ ๋ฌธ์ ๋ฅผ ์์ ํ์ต๋๋ค.
๋ณํ
import electron, { ipcRenderer } from 'electron'
์๊ฒ
const electron = window.require("electron")
@srinathh CRA ์ฑ์ ๋ฉ์ธ์์ ๋ ๋๋ฌ๋ก ์ด๋ป๊ฒ ๋ ธ์ถ/๋ก๋ํ๊ณ ์์ต๋๊น? ๋น์ ์ด ๋จผ์ ๊ตฌ์ถํ๊ณ ์์ต๋๊น (๊ทธ๋ฆฌ๊ณ html ์ ์ ๋ฆฌ์์ค ๊ฒฝ๋ก๋ฅผ ์์ ํ๊ณ ์์ต๋๊น)
์, ํ์ฌ ๋ด ์์
ํ๋ฆ์ ๊ธฐ๋ณธ์ ์ผ๋ก CRA ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ์ฌ npm run build
๋ฅผ ์คํํ ๋ค์ ์ ์๋ฅผ ์ฌ์ฉํ์ฌ build
ํด๋์์ ์ถ๋ ฅ์ ์คํํ๋ ๊ฒ์
๋๋ค. ์๋์ผ๋ก ์ ์ ๋ฆฌ์์ค ๊ฒฝ๋ก๋ฅผ ์์ ํ ํ์๊ฐ ์์ต๋๋ค. package.json
for CRA ์คํฌ๋ฆฝํธ์์ ์ด๋ ๊ฒ homepage
์ค์ ํ๋ฉด ๊ฒฝ๋ก๊ฐ ์ ์ ํ๊ฒ ์ค์ ๋ฉ๋๋ค.
"homepage": "./"
๋ํ public
ํด๋์ ์ ์ ์ฑ์ฉ main.js
๋ฐ package.json
๊ฐ ์์ต๋๋ค. ๋ฐ๋ผ์ ๋น๋๋ฅผ ์คํํ๋ฉด ์๋์ผ๋ก ๋ณต์ฌ๋๊ณ electron build/
๋ฅผ ์คํํ์ฌ ์ฑ์ ์์ํ ์ ์์ต๋๋ค.
๋๋ ์ค์ ๋ก ๊ฐ๋ฐ์ ์ํด ์ ์๋ก npm start
๋ฅผ ํ ์ ์๊ธฐ๋ฅผ ์ํ์ง๋ง ๊ทธ ์ผ์ ํ๋ ๋ฐฉ๋ฒ์ ์์๋ด์ง ๋ชปํ์ต๋๋ค. eject
ํ๊ณ ์คํฌ๋ฆฝํธ๋ฅผ ์์ผ๋ก ์์ ํด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค.
์ค์ ์ ์๋ฅผ ๋ณด๋ ค๋ฉด https://github.com/srinathh/snippetfu ๋ฅผ ์ฐธ์กฐํ์ญ์์ค.
์ ๋ Electron์ด ์๋๋ผ Node-Webkit(nw.js)์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
window.require
๋ฅผ ์ฌ์ฉํ๋ฉด ๋ด ๋ฌธ์ ๋ ํด๊ฒฐ๋์์ต๋๋ค. ๋๋จํ ๊ฐ์ฌํฉ๋๋ค!
@nukeop window.require
์ ๋ ์ํด์คฌ์ต๋๋ค ์ ๋ง ๊ฐ์ฌํฉ๋๋ค! ๐
@nukeop ๊ฐ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ง๋ง ํด๊ฒฐ๋์์ต๋๋ค window.require ํธ๋ฆญ, ์ ๋ง ๊ฐ์ฌํฉ๋๋ค!
window.require
๋ fs.existsSync is not a function
๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ง๋ง ๋ ๋ค๋ฅธ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. window.require
๋ ํจ์๊ฐ ์๋๋๋ค. ์ด๋ป๊ฒ ํด๊ฒฐํ ๊น์?
@steric85 browserify , babel ๋๋ webpack์ ์ฌ์ฉ ์ค์ด์ ๊ฐ์? ์ฝ๋๋ฅผ ๋ณํํด์ผ ํ ์๋ ์์ต๋๋ค.
@Alxmerino ์นํฉ ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
์ฝ๋๋ฅผ ์ปดํ์ผํ๊ณ ์๋์ง ํ์ธ
@steric85 , ๋๋ typescript์์ window.require is not a function
์ ์ง๋ฉดํ๊ณ ๋ค์๊ณผ ๊ฐ์ด ์์ ํ์ต๋๋ค.
declare global {
interface Window {
require: any;
}
}
const electron = window.require('electron');
๋ด Angular ์ฑ์ ์ ์์์ ipcRenderer์ ์ก์ธ์คํ๊ธฐ ์ํด ์์ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๊ณ ์์ง๋ง ipcRenderer ๋ฉ์์ง ์ฒ๋ฆฌ๊ธฐ๋ฅผ ์ฌ์ฉํ์ฌ Observable์ ์
๋ฐ์ดํธํ ๋ ๊ฐ๋ ๋ณ๊ฒฝ ๊ฐ์ง๊ฐ ์๋ํ์ง ์์ต๋๋ค.
Angular๊ฐ ipcRenderer๊ฐ EventEmitter์ด๊ณ ipcRenderer ์ด๋ฒคํธ๊ฐ ๋ค์ด์ฌ ๋ ๋ณ๊ฒฝ ๊ฐ์ง๋ฅผ ์คํํด์ผ ํ๋ค๋ ๊ฒ์ ๋ชจ๋ฅด๊ธฐ ๋๋ฌธ์
๋๊น?
Angular 2์์๋ applicationRef.tick()
๋ฅผ ํธ์ถํ์ฌ Angular์ ์ํ๋ฅผ ์๋ก ๊ณ ์น๋๋ก ๋ช
์์ ์ผ๋ก ์ง์ํ์ต๋๋ค. https://angular.io/api/core/ApplicationRef
@nukeop ๋ฐ @srinathh ์ ๋งค์ฐ ์ ์ฌํ ๋ฌธ์ ์ ์ง๋ฉดํ๊ณ ์์ต๋๋ค. ์ด ๊ธฐ์ฌ ๊ฐ์ด๋์ ๋ฐ๋ผ Electron + React + Webpack ํ๋ก์ ํธ๋ฅผ ์ค์ ํ์ต๋๋ค. ๋ง์ง๋ง์ ์์ฑ์๊ฐ window.require
๋ก ํธ๋ฆญ์ ์ธ๊ธํ์ต๋๋ค. ๋ด ํ๋ก์ ํธ์ require('electron')
๋ ๊ณณ๋ง ์์ต๋๋ค. Electron์ ์ง์
์ ๊ณผ ์ผ๋ถ React ๊ตฌ์ฑ ์์์ ํ์ํ JavaScript ์ปจํธ๋กค๋ฌ ํด๋์ค์ ์์ต๋๋ค. ๋ด Electron ์ง์
์ ํ์ผ์์๋ ๋จ์ํ const electron = require('electron');
๋ฅผ ์ํํฉ๋๋ค. ๋ฉ์ธ ํ๋ก์ธ์ค์์ ์คํ๋์ด์ผ ํ๊ธฐ ๋๋ฌธ์
๋๋ค(๋ง๋์?), ์ปจํธ๋กค๋ฌ ํด๋์ค์์ const Electron = window.require('electron').remote;
๋ค์์ const Jsonfile = Electron.require('jsonfile');
, ์ด๋ ๋ ๋๋ฌ ํ๋ก์ธ์ค์์ ์คํ ์ค์ด๋ฏ๋ก ์ด๋ฅผ ์ํํ๋ ๋ฐฉ๋ฒ์ด์ด์ผ ํฉ๋๋ค. ๊ทธ๋ฌ๋ ๋ค์๊ณผ ๊ฐ์ node_modules/electron/index.js์ 6๋ฒ์งธ ์ค์์ @nukeop ("TypeError: fs.ExistsSync๋ ํจ์๊ฐ ์๋๋๋ค")๊ณผ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
var fs = require('fs')
var path = require('path')
var pathFile = path.join(__dirname, 'path.txt')
if (fs.existsSync(pathFile)) {
module.exports = path.join(__dirname, fs.readFileSync(pathFile, 'utf-8'))
} else {
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')
}
node_modules/electron์ ์ญ์ ํ๊ณ ๋ค์ ์ค์น๋ฅผ ์๋ํ์ต๋๋ค.
์ ๋ macOS 10.12.6์์ Electron 1.7.5๋ฅผ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ๊ธฐ์ฌ์ ์ค์ ์ผ๋ก npm run dev
๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ก์ ํธ๋ฅผ ์์ํฉ๋๋ค.
์
๋ฐ์ดํธ; ๋ด ์ค๋ฅ๋ฅผ ์ผ์ผํจ require
์ ์ฐพ์์ต๋๋ค. React index.js์์ require('electron-react-devtools')
๋ฅผ ์๋ํ์ต๋๋ค. const ReactDevtools = Electron.require('electron-react-devtools');
๋ก ๋ณ๊ฒฝํ๋ฉด ์ค๋ฅ๊ฐ ์ค์ง๋์์ง๋ง ์ด์ ๋ ReactDevtools ์ธ์คํด์ค์์ .inject()
๋ฅผ ํธ์ถํ ์ ์๋ ๊ฒ ๊ฐ์ต๋๋ค("ํจ์๊ฐ ์๋๋๋ค"). ํ์ง๋ง ์ฌ๊ธฐ์ ๋
ผ์ํ ๋ด์ฉ์ด ์๋ ์๋ ์์ต๋๋ค. .
@steric85 ์นํ์ด์ง ํ๊ฒฝ์์ ์ฑ์ ์คํํ๊ธฐ ๋๋ฌธ์ ๋๋ค => Electron ํ๊ฒฝ(Nodejs ํ๊ฒฝ)์์ ์ฑ์ ์คํํด์ผ ํฉ๋๋ค
๋๋ ์ฌ์ ํ window.require is not a function
๋ฐ๊ณ ์์ต๋๋ค. ์ ๋ React Starter Kit(https://github.com/kriasoft/react-starter-kit)์ ํจ๊ป Electron์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์ด๊ฒ์ ์ ์ธํ๊ณ ๋ ๋ชจ๋ ๊ฒ์ด ์ ์๋ํฉ๋๋ค.
์น์์ ์ฑ์ ๋ก๋ํ๋๋ก Electron ์ฑ์ ์ค์ ํ์ผ๋ฏ๋ก ์ฑ์ด ๋ก์ปฌ์์ ์คํ๋์ง ์์ต๋๋ค.
https://gist.github.com/holgersindbaek/68f6db82f507967a51ca75c527faeff6
๋ด๊ฐํ๋ ค๋ ๊ฒ์ ๋ด React ํ์ผ ์ค ํ๋์์ ipcRenderer
๋ฅผ ํธ์ถํ๋ ๊ฒ์
๋๋ค. ๋ด ์ฑ์ด ์น์์ ๋ก๋๋ ๋๋ ๊ฐ๋ฅํ์ง ํ์คํ์ง ์์ต๋๋ค. ์ด๋ค ์ ์?
@holgersindbaek ํฌ๋กฌ, ํ์ด์ดํญ์ค ๋ฑ์ ๋ธ๋ผ์ฐ์ ์์ ์ฑ์ ๋ณด๋ฉด ์๋ฉ๋๋ค. ์นํ์ด์ง ํ๊ฒฝ์ด๊ธฐ ๋๋ฌธ์ ๋์ํ์ง ์์ต๋๋ค.
Electron ์ฐฝ์์ ์ฑ์ ํ์ธํด์ผ ํฉ๋๋ค.
์ ๋ ๊ทธ๋ ์ต๋๋ค. ํ์ง๋ง ์ด๋ค ์์ผ๋ก๋ Electron์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ๊ฐ ์คํ ์ ์น์ฌ์ดํธ์์ ์ฑ์ ๋ก๋ํ๋ ๊ฒ์ ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ์ ์ ์ฑ์ ์น์ฌ์ดํธ๋ฅผ ํ์ํ๊ณ ์์ต๋๋ค. ์ ํ์ผ์ ์ฐธ์กฐํ์ธ์. ์ ๋ง ๋ด๊ฐ ํ ์ ์๋ ์ผ์ด ์๋์ง ํ์ธํ๊ณ ์ถ์ ๋ฟ์ด์ผ?!
Electron์ ๋ชจ๋ URL์ ๋ก๋ํ ์ ์์ต๋๋ค. URL์ ๋ก๋ํ๋ ค๋ฉด ์ด ํจ์๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค. mainWindow.loadURL(url)
=> ์ ์ ์ฐฝ ๋ณด๊ธฐ์์ ํด๋น URL ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋๋ require, ipc ๋ฑ์ ์ก์ธ์คํ ์ ์์ต๋๋ค.
ํ์ธ. ๋๋ ๊ทธ๊ฒ์ ์๋ํ ๊ฒ์ด๋ค.
์ ์์ window.require
๋ ์๋ํ์ง ์์์ง๋ง window.require
์ ๋ํ fs
๋ ์๋ํ์ต๋๋ค.
์ด์ ๋ ํ์คํ์ง ์์ต๋๋ค. ๊ทธ๋ฌ๋ ๊ทธ๊ฒ์ ์๋ํ๊ณ ์์ผ๋ฉฐ ์์ ๊ฐ์ธ ํ๋ก์ ํธ์ด๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ๋ฅผ ํธ์ํ์ง ์์ ๊ฒ์ ๋๋ค.
@nukeop ๊ฐ์ฌํฉ๋๋ค
์๋ ํ์ธ์, ์ด๊ฒ์ ๋ด package.json์ ๋๋ค. ๋๋ webpack์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์ด๊ฒ๋ค ์ค ์ด๋ ๊ฒ๋ ๋ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ง ๋ชปํ์ต๋๋ค. ์๋ฌด๋ ํด๊ฒฐ์ฑ ์ ๊ฐ์ง๊ณ ์์ต๋๊น? window.require๋ฅผ ์ฌ์ฉํ ํ "window is not defined" ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
'์๊ฒฉํ ์ฌ์ฉ';
var ์ ์ = ํ์('์ ์')
var ์ฑ = ์ ์.์ฑ;
var BrowserWindow = ์ ์.BrowserWindow;
var ๋ฉ์ธ ์ฐฝ = null;
app.on('์ค๋น', function() {
mainWindow = new BrowserWindow({๋๋น: 800, ๋์ด: 600});
mainWindow.loadURL('file://' + __dirname + '/index.electron.html');
mainWindow.webContents.openDevTools();
});
๋๋ typescript๋ฅผ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ์ฌ์ฉํด์ผํ์ต๋๋ค.
const electron = (<any>window).require("electron");
๋ด ๋ ๋๋ฌ๊ฐ ๋ด ๋ฉ์ธ๊ณผ ํต์ ํ๋๋ก ํฉ๋๋ค. ์ด๊ฒ์ด ๋๊ตฐ๊ฐ๋ฅผ ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
์ด๊ฒ์ ๋๋ฅผ ์ํด ์ผํ์ต๋๋ค.
์๋ฅผ ๋ค์ด ์๊ฒฉ์ด ํ์ํ ๊ฒฝ์ฐ
const ์ฐฝ ์ ์ธ: ๋ชจ๋;
const { ์๊ฒฉ } = window.require('์ ์');
์๋ ํ์ธ์, ๊ฐ์ฌํฉ๋๋ค.
2017๋
12์ 3์ผ ์ผ์์ผ ์คํ 9์ 29๋ถ, Michael - แแซแคแ แฐแแ
[email protected]>์ ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
์ด๊ฒ์ ๋๋ฅผ ์ํด ์ผํ์ต๋๋ค.
์๋ฅผ ๋ค์ด ์๊ฒฉ์ด ํ์ํ ๊ฒฝ์ฐconst ์ฐฝ ์ ์ธ: ๋ชจ๋;
const { ์๊ฒฉ } = window.require('์ ์');โ
๋น์ ์ด ๋๊ธ์ ๋ฌ์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/electron/electron/issues/7300#issuecomment-348801405 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ARDyd4c3aOkMbb058xklujMMbnmaoxKGks5s8uGVgaJpZM4KDU6t
.
@solominh ์ฌ๊ธฐ ์ ์ค๋ช ํด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ๊ทธ๋ฌ๋ @holgersindbaek ๊ณผ ์ ์ฌํ ๊ตฌ์ฑ์ด ์์ต๋๋ค. ์ด๋ค ํ๊ฒฝ์ด webview์์ ์ฌ์ ๋ก๋ ์คํฌ๋ฆฝํธ์ ๋๊น?
์ ๋ณด:
mainWindow.loadURL(url)
๋ฅผ ์คํํฉ๋๋ค. ์ฌ๊ธฐ์ url์ ๋ก์ปฌ index.html์
๋๋ค.<webview>
๊ฐ ์์ต๋๋ค.preload
ํ๋๊ฐ ์์ผ๋ฉฐ ์ด ์คํฌ๋ฆฝํธ๋ window.require('electron')๋ฅผ ์ํํฉ๋๋ค.๋น๊ณ :
const electron = require('electron')
๋ฅผ ์ฌ์ฉํ๋ฉด fs.readFileSync is not a function
์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.const electron = window.require('electron')
๋ฅผ ์ฌ์ฉํ๋ฉด window.require is not a function
์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.ํธ์ง: <webview nodeintegration="true">
๋ฐ window.require๋ฅผ ์ฌ์ฉํ์ฌ ํด๊ฒฐํ์ต๋๋ค. ๋์ค์ ์ฐธ์กฐํ ์ ์๋๋ก ์ฌ๊ธฐ์ ๋ฉ๋ชจ๋ฅผ ๋จ๊น๋๋ค.
window.require๊ฐ ๋๋ฅผ ์ํด ์ผํ์ต๋๋ค! ๊ณ ๋ง์ ์๋ค์!
๋ด๊ฐ ์ด๊ฒ์ ์๋ํ์ ๋ ๋ธ๋ผ์ฐ์ ์ ์ค๋ฅ ๋ฉ์์ง
window.require()..
๋ ๋นํ์ฑํํ๋ nodeIntegration: false
๋๋๋ฆฌ๋ ๊ฒ์ ์์์ต๋๋ค. ๋ฉ์ฒญํ ์ค์. ๋๊ตฐ๊ฐ๊ฐ ํ ์๊ฐ ๋์ ์ฐ๊ตฌํ๋ ๋ฐ ๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
@phil294 ๊ณ ๋ง์์! ์กฐ์ฌํ๋ ๋ฐ ํ ์๊ฐ์ ์ ์ฝํ์ต๋๋ค.
์๋
ํ์ธ์ @micsel ์
๋๋ค .
๋๋ ์ ์ธ const ์ฐฝ์ ํฌํจํ์ต๋๋ค.
๊ทธ๋ฌ๋ ๊ตฌ๋ฌธ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
์ด๋ค ์์ด๋์ด๊ฐ ์์ต๋๊น?
์, ์ ์ธ const ์ฐฝ์ ๋ฃ์ต๋๋ค. ์๋จ, ์์ ํ์ด ์๋ ๋ฐ๋ก ๋ค์ ์์ต๋๋ค.
window.require๊ฐ ํจ์๊ฐ ์๋๊ณ Angular-CLI๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋ค์์ ์ฌ์ฉํ์ฌ Window ์ธํฐํ์ด์ค๋ฅผ ์ธ์คํด์คํํฉ๋๋ค.
./src/typings.d.ts
declare var window: Window;
interface Window {
require: any;
}
๊ทธ๋ฐ ๋ค์ ์ด๊ฒ์ ์ฌ์ฉํ์ฌ ์ ์๋ฅผ ํฌํจํ ์ ์์ต๋๋ค.
const { ipcRenderer } = window.require('electron');
์ ์ ์ฑ์์ ๊ฐ๋ 2+๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ "ngx-electron" lib๋ฅผ ๊ฐ์ ธ์์ any.componets.ts์์ ์ฌ์ฉํ์ญ์์ค.
import { ElectronService } from 'ngx-electron';
//constructor
constructor(
private elt: ElectronService
){
var fs = this.elt.remote.require('fs');
}
๋๋ ์ ์์ ํจ๊ป ๋ฐ์ js๋ฅผ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ์ด ์ค์ ํฐ๋ฏธ๋ ์์ฌ ์คํ ์์์ ์คํํ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. Uncaught Type Error: window.require is not a function ๋ด๊ฐ typescript๋ฅผ ์ฌ์ฉํ์ง ์์ต๋๋ค. ์ด๋ป๊ฒ React Js์์ ์ฐฝ์ ์ ์ธํฉ๋๊น?
์ฌ์ ํ ๋ฌธ์ ์ ์ง๋ฉดํ๊ณ ์๋ ์ฌ๋๋ค์ ์ด๋ป๊ฒ๋ window.require()
๋ฅผ ์ํํ๋ฉด ์ฝ๋๋ฒ ์ด์ค ์ ์ฒด์์ import
๋ฌธ์ ์ฌ์ฉํ๋ ์ผ๊ด์ฑ์ ๋ง์นฉ๋๋ค. ์ฌ์ด ๋์์ webpack target
์ electron-renderer
๋ก ์ค์ ํ๋ ๊ฒ์
๋๋ค. Create React App ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๊บผ๋ด๊ธฐ๊ฐ ์๋ง์ด ๋ ์ ์์ต๋๋ค. ๋ฐ๋ผ์ ์นํฉ ํํน์ ์ํํ๋ ์ด ํจํค์ง๋ฅผ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ ์๋ฅผ ๋ค์ด React ๊ตฌ์ฑ ์์(๋๋ ๋ค๋ฅธ ๋
ธ๋ ๋ชจ๋)์์ import fs from 'fs'
์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
Vue CLI 3์ด ์๋ ์ฐฝ์์ window.require๋ ์๋ํ์ง๋ง "node_modules/"์ ์๋ ๊ฒฝ๋ก ๋์ ์ ์ฒด ๊ฒฝ๋ก๊ฐ ํ์ํฉ๋๋ค.
ํ์ง๋ง React์ ๊ฒฝ์ฐ์ ๋ง์ฐฌ๊ฐ์ง๋ก vue.config.js๋ฅผ ์์ ํ์ฌ Vue์ ๋ง๊ฒ webpack์ ๊ตฌ์ฑํ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ฉด "require"๊ฐ ์์๋๋ก ์๋ํฉ๋๋ค.
vue.config.js:
module.exports = {
configureWebpack: config => {
if (process.env.NODE_ENV === 'production') {
config.output.publicPath = `${process.cwd()}/dist/`
}
config.target = 'electron-renderer'
}
}
router.js(์ด๊ฒ์ ๋จ์ง ์์ผ ๋ฟ์ด๋ฉฐ ๋ค๋ฅธ ๋ชจ๋ vue js ํ์ผ์์ ์๋ํฉ๋๋ค)
const Store = require("electron-store");
const store = new Store();
_๋๋ ์ด๊ฒ์ ์ถ๊ฐํ๊ณ ์ถ์ง ์์ง๋ง ๋๋ฒ๊น ํ๋ ๋ฐ ํ๋ ์๊ฐ์ ์ ์ฝํ ์ ์์ต๋๋ค._
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ค๋ฉด rm -rf node_modules && npm install
ํด์ผ ํ์ต๋๋ค. ๊ทธ๋ฐ ๋ค์ window.require
window
๋ฅผ ์ ๊ฑฐํ ์ ์์๊ณ ์์
์ด ๋ค์ ์์๋์์ต๋๋ค. ๋ฐ๋ผ๊ฑด๋ ๊ทธ๊ฒ์ด ๋ค๋ฅธ ๋๊ตฐ๊ฐ๋ฅผ ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
@cperthuis ๊ฐ์ฌํฉ๋๋ค!! ใ
ใ
์ ๋ Vue๋ ์ฌ์ฉํ์ง ์๊ณ ์์ง๋ง ๋
ผ๋ฆฌ์ ์ธ ์๊ฐ์ผ๋ก webpack.config.js๋ฅผ ๋์ ์์ฑ์ผ๋ก ๋ณ๊ฒฝํ ์ ์๋ค๋ ๊ฒ์ ์๊ฒ ๋์์ต๋๋ค. :)
๋งค๋ ฅ์ฒ๋ผ ์ผํ์ต๋๋ค.
์๋ ,
window.require
๋ ๊ฐ๋ฐ ๋ก์ปฌ ์๋ฒ ํ๊ฒฝ์์ ์๋ํ์ง๋ง ์ถ์๋ HTML ํ์ผ์ React ์ฑ์ ๋น๋ํ ํ ํ๋ก๋์
ํ๊ฒฝ์์๋ ์๋ํ์ง ์์ต๋๋ค.
function createWindow() {
win = new BrowserWindow({
width: 1280,
height: 720,
icon: path.join(__dirname, 'assets/icons/png/64x64.png'),
webPreferences: {
nodeIntegration: true,
preload: __dirname + '/preload.js'
}
})
win.setPosition(0, 0)
win.loadURL(isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, 'build/index.html')}`)
}
localhost:3000
์์๋ ์๋ํ์ง๋ง file://${path.join(__dirname, 'build/index.html')}
์์๋ ์๋ํ์ง ์์ต๋๋ค.
@cperthuis , 'react-app-rewired'๋ฅผ ์ฌ์ฉํ์ฌ ๊บผ๋ด์ง ์์ CRA ์ฑ์์ ์์ ์ฌํญ์ด ์๋ํ์ต๋๋ค. ๊ฐ์ฌ ํด์.
Create-React-App 2์์๋ craco
npm ๋ชจ๋์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
https://www.npmjs.com/package/@craco/craco
package.json์์ craco
react-scripts
๋ณ๊ฒฝ
craco.config.js
module.exports = {
webpack: {
configure: {
target: 'electron-renderer'
}
}
};
๊ทธ๋ฆฌ๊ณ ๋ค์๊ณผ ๊ฐ์ด Electron ์ปจํ ์คํธ์ ์ก์ธ์คํ ์ ์์ต๋๋ค.
import Electron from 'electron';
const { dialog } = Electron.remote;
@Maxou44 craco & electron์ ๋ํ ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค. ๊ทธ๊ฒ์ ๋ด๊ฐ ํ์๋ก ํ ๊ฒ์ ๋๋ค. ๋๊ตฐ๊ฐ๊ฐ ์๋ฅผ ์ฐพ๊ณ ์๋ค๋ฉด ...
@wwlib ๋ฌธ์ ์์ต๋๋ค. ๋์์ด ๋์ จ๋ค๋ ๋คํ์ ๋๋ค ๐ฅณ
window.require()..
๋ ๋นํ์ฑํํ๋nodeIntegration: false
๋๋๋ฆฌ๋ ๊ฒ์ ์์์ต๋๋ค. ๋ฉ์ฒญํ ์ค์. ๋๊ตฐ๊ฐ๊ฐ ํ ์๊ฐ ๋์ ์ฐ๊ตฌํ๋ ๋ฐ ๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
์ ๋ง ๊ณ ๋ง์ต๋๋ค.
์๊ฒฉ ์ฝํ
์ธ ๋ฅผ ๋ก๋ํ๋ ๊ฒฝ์ฐ nodeIntegration
๋ฅผ false๋ก ์ค์ ํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค. https://electronjs.org/docs/tutorial/security#2 -disable-nodejs-integration-for-remote -์ฝํ
์ธ
์๋
,
๊ฐ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. window.require๋ฅผ ์ฌ์ฉํ ๋ Uncaught TypeError: fs.readFileSync is not a function
์ค๋ฅ๊ฐ ์์ ๋์์ง๋ง Uncaught TypeError: window.require is not a function
๋ ๋ค๋ฅธ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์ ์ ์ฌํญ์ด ์์ต๋๊น? ๋ ธ๋ js์์ browserify๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
$ BrowserWindow
๋ฅผ ์ ์ธํ ๋ nodeIntergation
๋ฅผ true
$๋ก ๋ช
์์ ์ผ๋ก ์ ์ธํ์ง ์๋ ํ window.require is not a function
์ค๋ฅ๊ฐ ๊ณ์ ๋ฐ์ํฉ๋๋ค.
new BrowserWindow({
webPreferences: {
nodeIntegration: true,
}
});
๋ด๊ฐ ์ฐพ์ ์ ์ผํ ํด๊ฒฐ์ฑ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
react-app-rewired
ํจํค์ง๋ก ์ค์นeject
์์ด ์ฌ์ฉ์ ์ ์ Webpack ๊ตฌ์ฑ์ ์ฝ์
ํ๋ ค๋ฉด ์ด ๋ชจ๋์ ์ฌ์ฉํ์ญ์์ค. "scripts": {
...
"start": "react-app-rewired start",
},
config-overrides.js
ํ์ผ์ ์ถ๊ฐํฉ๋๋ค.module.exports = function override (config, env) {
config.target = 'electron-renderer'
return config;
}
@Lilanga comment , @agrublev comment ๋ฐ react-app- rewired ์ ์์ ๋๋ถ์ ๋๋ค.
์
๋ฐ์ดํธ๋จ:
์ค์ ๋ก ๋์ผํ ์์
์ ์ํํ๋ ๋ฐฉ๋ฒ์ ๋ ๋ฒ์งธ ๋ฒ์ : https://www.codementor.io/randyfindley/how-to-build-an-electron-app-using-create-react-app-and-electron-builder-ss1k0sfer
์
๋ฐ์ดํธ๋จ2:
@nukeop Browserify ๋ฅผ ์ฌ์ฉํ์ง ์๋ ์ด์ ๋๋ ์ฌ์ฉํด์ผ ํ๋ ์ด์ ์ ๋ํ ํ ๋ก ์ ๋ฐ๋ฅผ ์๊ฐ์ด ๋ถ์กฑํ์ฌ ์คํด์ ์์ง๊ฐ ์๋ ์ผ๋ถ ์ง์ ์ ์ญ์ ํ์ผ๋ฉฐ ์ง๊ธ ๋ด๊ฐ ์๋ฏธํ๋ ๋ฐ์ ๋ํ ์์ธํ ์ค๋ช
์ ์์ฑํ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ " window.require
๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋๋ค"๋ ๊ฒ์ด ๋งค์ฐ ์ ๋ขฐํ ์ ์๋ ๊ฒ์ฒ๋ผ ๋ณด์ธ๋ค๋ ๊ฐ์ธ์ ์ธ ๊ฒฌํด๋ฅผ ์ ์งํ๊ฒ ์ต๋๋ค.
์๋ชป๋ ๋ฐฉ๋ฒ?
Electron ํ๊ฒฝ ๋ด์์ ์คํ๋์ด์ผ ํ๋ React ์ฑ์ ๋๋ค. ๊ทธ ๋ฐ๋์ ๊ฒฝ์ฐ๋ ๋ง์ฐฌ๊ฐ์ง์ ๋๋ค.
๋ญ?
_๋๋ ์ด๊ฒ์ ์ถ๊ฐํ๊ณ ์ถ์ง ์์ง๋ง ๋๋ฒ๊น ํ๋ ๋ฐ ํ๋ ์๊ฐ์ ์ ์ฝํ ์ ์์ต๋๋ค._
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ค๋ฉด
rm -rf node_modules && npm install
ํด์ผ ํ์ต๋๋ค. ๊ทธ๋ฐ ๋ค์window.require
window
๋ฅผ ์ ๊ฑฐํ ์ ์์๊ณ ์์ ์ด ๋ค์ ์์๋์์ต๋๋ค. ๋ฐ๋ผ๊ฑด๋ ๊ทธ๊ฒ์ด ๋ค๋ฅธ ๋๊ตฐ๊ฐ๋ฅผ ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
์์ฐ.. ์ด ์ค๋ ๋์์ ๋ชจ๋ ๊ฒ์ ์๋ํ์ง๋ง ์ถ์ฒ์ด ์๊ธฐ ๋๋ฌธ์ ๋ค์ ๋ณด๊ธฐ๋ฅผ ๋์ณค์ต๋๋ค. ์ฌ์ ํ window is not a function
๋ฐ์์ต๋๋ค.
node_modules
๋ฐ ์๋์ ์ ๊ฑฐํ๊ณ ๋ค์ ์ค์นํ์ต๋๋ค.
์ถ์ : ์ฌ์ ํ ๋ชจ๋ ์๋ฃจ์
์ ์ํํด์ผ ํ์ง๋ง ๋ชจ๋ ์์
์ ์ํํ๋ค๋ฉด
์ฌ์ ํ ๋์ผํ ์ฌ์ค์น node_modules
๋น์ ์ ๋์ ํ๋ฃจ๋ฅผ ๊ตฌํ์ต๋๋ค @joshuapinter !
react-create-app์ ์ฌ์ฉํ์ฌ ๋์ผํ ์ค๋ฅ๋ฅผ ๋ฐ๊ฒฌํ์ต๋๋ค.
์ง๊ธ๊น์ง์ ์๋ฃจ์
์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
const electron = window.require("electron")
์ ์ ๋ถ๋ถ BrowserWindow
์ nodeIntegration:true
๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์ถ๊ฐํฉ๋๋ค.
mainWindow = new BrowserWindow({ width: 900, height: 680, webPreferences: { webSecurity: false, nodeIntegration: true } });
๋ด๊ฐ ์ฐพ์ ์ ์ผํ ํด๊ฒฐ์ฑ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- ๊ฐ๋ฐ์ ์ข ์์ฑ
react-app-rewired
ํจํค์ง๋ก ์ค์น- CRA๋ฅผ
eject
์์ด ์ฌ์ฉ์ ์ ์ Webpack ๊ตฌ์ฑ์ ์ฝ์ ํ๋ ค๋ฉด ์ด ๋ชจ๋์ ์ฌ์ฉํ์ญ์์ค."scripts": { ... "start": "react-app-rewired start", },
- ๋ค์ ๋ด์ฉ๊ณผ ํจ๊ป
config-overrides.js
ํ์ผ์ ์ถ๊ฐํฉ๋๋ค.module.exports = function override (config, env) { config.target = 'electron-renderer' return config; }
@Lilanga comment , @agrublev comment ๋ฐ react-app- rewired ์ ์์ ๋๋ถ์ ๋๋ค.
์ ๋ฐ์ดํธ๋จ:
์ค์ ๋ก ๋์ผํ ์์ ์ ์ํํ๋ ๋ฐฉ๋ฒ์ ๋ ๋ฒ์งธ ๋ฒ์ : https://www.codementor.io/randyfindley/how-to-build-an-electron-app-using-create-react-app-and-electron-builder-ss1k0sfer์ ๋ฐ์ดํธ๋จ2:
@nukeop Browserify ๋ฅผ ์ฌ์ฉํ์ง ์๋ ์ด์ ๋๋ ์ฌ์ฉํด์ผ ํ๋ ์ด์ ์ ๋ํ ํ ๋ก ์ ๋ฐ๋ฅผ ์๊ฐ์ด ๋ถ์กฑํ์ฌ ์คํด์ ์์ง๊ฐ ์๋ ์ผ๋ถ ์ง์ ์ ์ญ์ ํ์ผ๋ฉฐ ์ง๊ธ ๋ด๊ฐ ์๋ฏธํ๋ ๋ฐ์ ๋ํ ์์ธํ ์ค๋ช ์ ์์ฑํ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ "window.require
๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋๋ค"๋ ๊ฒ์ด ๋งค์ฐ ์ ๋ขฐํ ์ ์๋ ๊ฒ์ฒ๋ผ ๋ณด์ธ๋ค๋ ๊ฐ์ธ์ ์ธ ๊ฒฌํด๋ฅผ ์ ์งํ๊ฒ ์ต๋๋ค.
์ด๊ฒ์ ๋๋ฅผ ์ํด ์ผํ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค
window.require
์ ๋ฌธ์ ์ ์ ์ต์์ ํจํค์ง์์๋ง ์๋ํ๋ค๋ ๊ฒ์
๋๋ค.
์๋ฅผ ๋ค์ด fs
๋ฅผ ์ง์ ์ฌ์ฉํ๋ฉด ์๋ํฉ๋๋ค. ๊ทธ๋ฌ๋ fs
์ ๋ํ ์ข
์์ฑ์ด ์๋ ํจํค์ง๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ฌ์ ํ ์์ธ๊ฐ ๋ฐ์ํฉ๋๋ค.
window.require
React App ๋ด์์ ํจ์๋ฅผ ํธ์ถํ ๋ ์๋ํ์ง ์์ต๋๋ค. "TypeError: window.require๋ ํจ์๊ฐ ์๋๋๋ค"๋ผ๋ ๋ฉ์์ง๊ฐ ๋ํ๋ฉ๋๋ค.
App.js
:
```์๋ฐ์คํฌ๋ฆฝํธ
'๋ฐ์'์์ React, { useEffect, useState } ๊ฐ์ ธ์ค๊ธฐ;
๊ฐ์ ธ์ค๊ธฐ './App.css';
const ipcRenderer = window.require('์ ์').ipcRenderer;
ํจ์ ์ฑ() {
useEffect( () => {
ipcRenderer.on('ping', (event, message) => { console.log(message) });
}, []);
return (
<div className = 'App'>
<div className = 'Header-Arrow'></div>
<div className = 'Box'>
<p>Press โ + โง + 4</p>
</div>
</div>
);
}
๊ธฐ๋ณธ ์ฑ ๋ด๋ณด๋ด๊ธฐ;
````
Main.js
์ ๋ฉ์ธ ์ฐฝ ๋ณ์:
```์๋ฐ์คํฌ๋ฆฝํธ
// ๋ธ๋ผ์ฐ์ ์ฐฝ์ ์์ฑํฉ๋๋ค.
mainWindow = ์๋ก์ด BrowserWindow({
AlwaysOnTop: ์ฌ์ค,
ํ๋ ์: ๊ฑฐ์ง,
์ ์ฒด ํ๋ฉด ๊ฐ๋ฅ: ๊ฑฐ์ง,
ํฌ๋ช
: ์ฌ์ค,
titleBarStyle: 'customButtonsOnHover',
ํ์: ๊ฑฐ์ง,
๋๋น: 300,
ํค: 350,
์น ๊ธฐ๋ณธ ์ค์ : {
nodeIntegration: ์ฐธ,
์ฌ์ ๋ก๋: __dirname + '/preload.js'
}
});
```
**
Preload.js`**:
javascript
window.ipcRenderer = require('electron').ipcRenderer;
๋ด๊ฐ ๋ฌด์์ ๋์น๊ณ ์์ต๋๊น?
๊ทธ๋์, ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค. ๋๊ตฐ๊ฐ๊ฐ ํํ์ ๋ณผ ์ ์๊ธฐ ๋๋ฌธ์ ๋๋ ์ค์ค๋ก ๋๋ตํฉ๋๋ค (๋ช ์๊ฐ ๋์ ๋ถ์ด์์์ต๋๋ค). Preload.js
ํ์ผ์ด ์์ผ๋ฉด รpp.js
(๋ ๋๋ฌ)์์ window.require('electron').ipcRenderer
๋ฅผ ๋ค์ ํธ์ถํ ํ์๊ฐ ์์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ด window.ipcRenderer
๋ณ์๋ฅผ ์ง์ ํธ์ถํฉ๋๋ค.
App.js
:
````์๋ฐ์คํฌ๋ฆฝํธ
'๋ฐ์'์์ React, { useEffect, useState } ๊ฐ์ ธ์ค๊ธฐ;
๊ฐ์ ธ์ค๊ธฐ './App.css';
ํจ์ ์ฑ() {
useEffect( () => {
window.ipcRenderer.on('ping', (event, message) => { console.log(message) });
}, []);
return (
<div className = 'App'>
<div className = 'Header-Arrow'></div>
<div className = 'Box'>
<p>Press โ + โง + 4</p>
</div>
</div>
);
}
๊ธฐ๋ณธ ์ฑ ๋ด๋ณด๋ด๊ธฐ;
````
Main.js
์ ๋ฉ์ธ ์ฐฝ ๋ณ์:
javascript
// Create the browser window.
mainWindow = new BrowserWindow({
alwaysOnTop: true,
frame: false,
fullscreenable: false,
transparent: true,
titleBarStyle: 'customButtonsOnHover',
show: false,
width: 300,
height: 350,
webPreferences: {
nodeIntegration: true,
preload: __dirname + '/preload.js'
}
});
Preload.js
:
javascript
window.ipcRenderer = require('electron').ipcRenderer;
๋ช ๋ น์ค์์ ์ฑ์ ์คํํ ํ React ํ๋ก์ธ์ค์ ์ํด ์์ฑ๋ ์ฐฝ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค(ipcRenderer๊ฐ ์ ์๋์ง ์์). ๋ฌด์ํด. Electron ํ๋ก์ธ์ค(๋ฉ์ธ ์ฑ)์ ์ํด ์์ฑ๋ ์ฐฝ์ ์ ์์ ์ผ๋ก ์๋ํฉ๋๋ค.
Create-React-App 2์์๋
craco
npm ๋ชจ๋์ ์ฌ์ฉํ ์ ์์ต๋๋ค.https://www.npmjs.com/package/@craco/craco
package.json์์
craco
react-scripts
๋ณ๊ฒฝcraco.config.js
module.exports = { webpack: { configure: { target: 'electron-renderer' } } };
require("fs")
๋ฟ๋ง ์๋๋ผ window.require("fs")
๋์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ด ํ ๋ก ์์ CRACO๋ฅผ ์๊ฐํ @Maxou44 ์๊ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ํ๋ก์ ํธ์์ 3๊ฐ์ง๋ฅผ ๋ณ๊ฒฝํ์ต๋๋ค.
new BrowserWindow({ width: 1200, height: 800 })
new BrowserWindow({ width: 1200, height: 800, webPreferences: { nodeIntegration: true } })
const fs = require("fs")
์ const fs = require("electron").remote.require("fs")
๋ก ๋์ฒด์์ธํ ์ค๋ช ์ @wwlib ์ ์ด git repo๋ฅผ ์ฐธ์กฐํ์ญ์์ค. https://github.com/wwlib/cra-craco-electron-example
์ ์ฒด ์ค๋ ๋๋ฅผ ์์์ ์๋๋ก ์ฝ์์ง๋ง ์๋ฌด ๊ฒ๋ ์๋ํ์ง ์์์ต๋๋ค.
์์ @Saroopashree ๋ฐฉ๋ฒ์ ์ ์ธํ๊ณ . ์๋ฃจ์
์ ๊ณต์ ํด ์ฃผ์ @Saroopashree ์๊ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
์ค๋ ๋๊ฐ ์์๋ ์ดํ๋ก react์ webpack์ด ๋ค์ ๋ณ๊ฒฝ๋์๊ธฐ ๋๋ฌธ์ ์์ ์๋ฃจ์
์ ๋ ์ด์ ์ฌ์ฉ๋์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ฌผ๋ก ํ๋ฆด โโ์๋ ์์ง๋ง ์์ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ฉด ํจ๊ณผ๊ฐ ์์ต๋๋ค.
์ด๊ฒ์ด ๋ด๊ฐ ํ ์ผ์
๋๋ค.
npm install craco -D
์คํmodule.exports = {
webpack: {
configure: {
target: 'electron-renderer'
}
}
};
new BrowserWindow({ width: 1200, height: 800, webPreferences: { nodeIntegration: true } })
๋ฅผ ์
๋ฐ์ดํธํ์ต๋๋ค. ๋ฌผ๋ก ๋๋น์ ๋์ด๊ฐ ๋ค๋ฆ
๋๋ค.npm start
๋ฅผ ์คํํ์ฌ create-react-app์ ์ฌ์ฉํ์ฌ ๋ง๋ ๋ฐ์ ์ฑ์ฉ ๊ฐ๋ฐ ์๋ฒ๋ฅผ ์์ํ์ต๋๋ค. ์ด๊ฒ์ ๋์ผํ ์ค๋ฅ๊ฐ ์๋ ํญ์ ์ด์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋๋ ๋ค์ ํผ๊ณคํจ์ ๋๊ผ๋ค.npm run electron
๋ฅผ ์คํํ์ฌ ์ ์ ์ฑ์ ์คํํ์ต๋๋ค.@Saroopashree๋ ๊ฐ์ฌํฉ๋๋ค.
๋ฐ์ ๊ตฌ์ฑ ์์/ํด๋์ค ๋ด์ '์ ์' ๋๋ ๋ค๋ฅธ ๊ตฌ์ฑ ์์์ ์ก์ธ์คํ๋ ค๋ ๊ฒฝ์ฐ ๋ค์์ ์๋ํ์ญ์์ค. #336757899
์ ์๊ฒ ์ ํฉํ ์๋ฃจ์ ์ ๋ํ ๋งํฌ๋ฅผ ๊ฒ์ํด ์ฃผ์ @tumbledwyer ์๊ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
์ ๋ฐ์ดํธ๋จ:
์ค์ ๋ก ๋์ผํ ์์ ์ ์ํํ๋ ๋ฐฉ๋ฒ์ ๋ ๋ฒ์งธ ๋ฒ์ : https://www.codementor.io/randyfindley/how-to-build-an-electron-app-using-create-react-app-and-electron-builder-ss1k0sfer
Randy Findley์ ์๋ฃจ์
:
์ด์ ๋ด๊ฐ ํ๋ ๊ฒ์ฒ๋ผ fs
๋ชจ๋์ ์ก์ธ์คํด์ผ ํ๋ ๊ฒฝ์ฐ ๋น ๋ฅด๊ฒ Module not found
์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
๋จผ์ Rescripts ๋ฅผ ์ค์นํฉ๋๋ค.
yarn add @rescripts/cli @rescripts/rescript-env --dev
๊ทธ๋ฐ ๋ค์ package.json์ ์คํฌ๋ฆฝํธ ํ๊ทธ๋ฅผ ๋ค์์์ ๋ณ๊ฒฝํ์ญ์์ค.
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
์ด์
"start": "rescripts start",
"build": "rescripts build",
"test": "rescripts test",
์ด์ ๋ค์ ๋ด์ฉ์ด ํฌํจ๋ .rescriptsrc.js
๋ผ๋ ์ ํ์ผ์ ์ถ๊ฐํฉ๋๋ค.
module.exports = [require.resolve('./.webpack.config.js')]
๋ง์ง๋ง์ผ๋ก ๋ค์ ๋ด์ฉ์ด ํฌํจ๋ .webpack.config.js
๋ผ๋ ๋ค๋ฅธ ์ ํ์ผ์ ์ถ๊ฐํฉ๋๋ค.
// define child rescript
module.exports = config => {
config.target = 'electron-renderer';
return config;
}
์ด์ fs
๋ชจ๋์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๊ฑฑ์ ํ์ง ๋ง์ธ์.
@ledleds ๊ฐ ์ง์ ํ ๊ฒ์ typscript ๋ฐ Electron๊ณผ ํจ๊ป CRA๋ฅผ ์ฌ์ฉํ์ฌ ์ ์๊ฒ ํจ๊ณผ์ ์ด์์ต๋๋ค. ๊ทธ๋ ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด webPreferences๋ฅผ ์ ์ธํ์ต๋๋ค.
webPreferences: {
preload: path.join(__dirname, 'preload.js')
},
nodeIntegration์ ๋ฎ์ด์ฐ๊ฑฐ๋ false๋ก ์ค์ ํ๋ ๊ฒ ๊ฐ์ผ๋ฏ๋ก true๋ก ์ค์ ํ๊ณ ์ฑ์ ๋ค์ ์์ํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๋ค(ํด๋น ๊ตฌ์ฑ์ผ๋ก Electron ์ฐฝ์ ๋ก๋ํ๋ ค๋ฉด ์ฑ์ ๋ค์ ์์ํด์ผ ํจ).
๋ค์๊ณผ ๊ฐ์ด nodeIntegration์ true๋ก ์ค์
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true
},
$
BrowserWindow
๋ฅผ ์ ์ธํ ๋nodeIntergation
๋ฅผtrue
$๋ก ๋ช ์์ ์ผ๋ก ์ ์ธํ์ง ์๋ ํwindow.require is not a function
์ค๋ฅ๊ฐ ๊ณ์ ๋ฐ์ํฉ๋๋ค.new BrowserWindow({ webPreferences: { nodeIntegration: true, } });
๋ฐ์ ์ฑ ์ฌ์ฐ๊ฒฐ
์ด๊ฒ์ ํ์ฅ์ฑ ์ธก๋ฉด์์ ๋ด๊ฐ ์ฐพ์ ์ ์ผํ ์ข์ ์๋ฃจ์ ์ด์์ต๋๋ค. ์๋ฌด๋ window.require์ ์์กดํด์ผ ํ๋ค๊ณ ์๊ฐํ์ง ์์ต๋๋ค.
window.require๋ฅผ ํ์ฅํ ์ ์๋ ์ด์ ๋ ๋ฌด์์ ๋๊น?
์ด ๋ฌธ์ ๋๋ ์ด์ ์ ์ฌํ ๋ฌธ์ ๋ก ์ด๋ ค์์ ๊ฒช๊ณ ์๊ณ Vue ๋ฐ vue-electron-builder๋ฅผ ์ฌ์ฉํ๋ ์ฌ๋์ ์ฌ๊ธฐ ๋ฅผ ์ฐธ์กฐํ์ญ์์ค.
๋ฐ์ ๋ฒํผ์ ํตํด ์ ์ ์์ฉ ํ๋ก๊ทธ๋จ์ ์ข ๋ฃํ๋ ๊ฒ๊ณผ ๊ด๋ จํ์ฌ ์ฌ์ ํ ์ด๊ฒ์ผ๋ก ์ด๋ ค์์ ๊ฒช๊ณ ์๋ ์ฌ๋์ ๊ณ์ ์ฝ์ผ์ญ์์ค.
์ ์๊ฒ ๋์์ด ๋ ๊ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
์ฐฝ์ ์ ์ธํ ๋ ๋ณด์์์ ์ด์ ๋ก ํ์ฌ ๊ธฐ๋ณธ์ ์ผ๋ก false
nodeIntegration: true
๋ฅผ ์ค์ ํ๋์ง ํ์ธํ์ญ์์ค. ์ผ๋ฐ์ ์ผ๋ก electron.js
ํ์ผ์์ ์ํ๋ฉ๋๋ค.
@packetstracer ๊ฐ ์ด๋ฏธ ์ธ๊ธํ๋ฏ์ด: _ํด๋น ๊ตฌ์ฑ์ผ๋ก Electron ์ฐฝ์ ๋ก๋ํ๋ ค๋ฉด ์ฑ์ ๋ค์ ์์ํด์ผ ํฉ๋๋ค_
mainWindow = new BrowserWindow({
//...
webPreferences: {
nodeIntegration: true,
},
});
electron.js
์์ ์๋จ ๊ทผ์ฒ์ ๋ค์ ๋ช
๋ น๋ฌธ์ ๋ฃ์ผ๋ฉด ipcMain
๊ฐ _"close-me"_ ์ด๋ฒคํธ๋ฅผ ์์ ํ ์ ์์ต๋๋ค.const { ipcMain } = require("electron");
ipcMain.on("close-me", (evt, arg) => {
app.quit();
});
window.require
๋ฌธ์ ์ถ๊ฐํฉ๋๋ค. ์ผ๋ฐ์ ์ธ require
๊ฐ ์๋ํ์ง ์์์ต๋๋ค .const ipcRenderer = window.require("electron").ipcRenderer;
<Button label="close" onClick={(e) => ipcRenderer.send("close-me")} />
์์ ๋กญ๊ฒ ์๊ฒฌ์ ๋งํ๊ณ ํผ๋๋ฐฑ์ ์ ๊ณตํ์ญ์์ค. ์ ๋ ์์ง ์ ์๋ฅผ ์ฒ์ ์ ํฉ๋๋ค.
์ข
๋ฃ ๋ฒํผ์ด ์๋ ์ปจํ
์คํธ๊ฐ ๊ด๋ จ์ด ์๋ค๋ ๊ฒ์ ์๊ณ ์์ง๋ง ๋ ์ ํฉํ ์ค๋ ๋๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. ๋ค๋ฅธ ์ ์ ํ ์ค๋ ๋๊ฐ ์์ผ๋ฉด ์ธ์ ๋ ์ง ์๋ ค์ฃผ์ธ์.
๋ด ๊ตฌ์ฑ:
"electron": "9.2.0",
"electron-builder": "22.8.0",
"electron-packager": "15.0.0",
๋๋ฅผ ์ํด ํด๊ฒฐ!! @nukeop ๊ฐ์ฌํฉ๋๋ค
`
`
typescript์์ ์ ์ ํ ์ ํ์ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ์๋ ์ฌ๋์ด ์์ต๋๊น?
๋๋ ํ์ฌ ๋ค์์ ๊ฐ์ง๊ณ ์๋ค
export const electron = window.require('electron').remote
๋๋ ๊ฐ์ ๊ฒ์ ์ํ๋ค
export const electron = window.require('electron').remote as ElectronType
๋ฐ๋ผ์ IDE๋ ์ ์ API๋ฅผ ์๋ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์์ต๋๋ค.
@timsamart ์๋ํฉ๋๋ค. ๋๋ถ์ ์์ ์๊ฐ์ ์ ์ฝํ ์ ์์ต๋๋ค. ๐คฃ
์์ ๋ชจ๋ ๊ฒ์ ๋ฌธ์ ๊ทธ๋๋ก ์๋ํ๋ ๋ฐ ๋ง์ ์๊ฐ์ ๋ณด๋ธ ํ์ BrowserView
๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์ ๋๋นํ์ฌ $# BrowserWindow
์ฒ๋ผ node.js๋ฅผ ๋ช
์์ ์ผ๋ก ํ์ฑํํด์ผ ํ๋ ๋ถ๋ถ์ ๋์ณค์ต๋๋ค.
new BrowserView({ // is a BrowserView not a BrowserWindow
webPreferences: {
nodeIntegration: true,
},
})
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ฏธ๋์ ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ณ ์ด ์ค๋ ๋๋ฅผ ์ฝ๋ ์ฌ๋์๊ฒ๋ require ๋์
window.require
๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ ์์ browserify์require
ํจ์ ๊ฐ์ ์ถฉ๋์ ํผํ ์ ์๋ ํ ๊ฐ์ง ๊ฐ๋ฅ์ฑ์ ๋๋ค.