このようなディレクトリでアプリを作成しています。
-electron app -node_modules -src -compiled -css -html -scripts -mainWindow.js -pug -sass -gulpfile.js -index.js -package.json -index.html
そして、上のmainWindow.js
からelectron
をrequire
したいですが、node_modules
フォルダが上の階層にあるためかできません。
環境変数を使えばこの問題を解決できると思ったのですが、むやみに環境変数を汚したくないので、別の方法を探しています。
試したこと
node_modulesフォルダ
と同じ階層にあるindex.js
からはelectron
がrequire
できているので、そこの階層までもどせばいいんだと思い、mainWindow.js
で
javascript
1const {BrowserWindow} = require("../../../electron").remote;
という風に指定を行いましたが、モジュールが見つからなかったのか、BrowserWindow
にはnull
が入ってしまいました。
どなたか、scriptsフォルダ
内のmainWindow.js
から、上の階層のnode_modules
にあるelectron
をrequire
する方法を教えていただけませんか?
package.json
json
1{ 2 "name": "electron_app", 3 "version": "1.0.0", 4 "description": "electron introduction", 5 "main": "index.js", 6 "scripts": { 7 "test": "echo \"Error: no test specified\" && exit 1", 8 "start": "gulp && electron .", 9 "gulp": "gulp", 10 "gulp-sass": "gulp sass", 11 "gulp-pug": "gulp pug" 12 }, 13 "keywords": [], 14 "author": "", 15 "license": "ISC", 16 "devDependencies": { 17 "electron": "^2.0.2", 18 "gulp": "^4.0.0", 19 "gulp-plumber": "^1.2.0", 20 "gulp-pug": "^4.0.1", 21 "gulp-sass": "^4.0.1" 22 } 23}
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。