问题
This is my directory structure where renderer.js
is included by index.html
.
The python scripts visitor.py
and download.py
are called from renderer.js
via python-shell.
Once I bundle, it is not able to find the python scripts
|_ index.html
|_ styles.css
|_ main.js
|_ package.json
|_ dist/
|_ node_modules/
|_ renderer.js
|_ visitor.py
|_ download.py
I tried putting everything in files: [...]
in package.json
under build > files
and then ran npm run dist
.
I also tried copying python files to dist
folder explicitly and then ran npm run dist
.
None are working.
/Application/test.app/Contents/Resources/app.asar/remderer.js:226 Error: python: can't open file 'visitor.py': [Error 2] No such file or directory
This is my package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron .",
"pack": "build --dir",
"dist": "build"
},
"author": "",
"license": "ISC",
"build": {
"appId": "com.example.app",
"files": [
"dist/",
"node_modules/",
"index.html",
"main.js",
"package.json",
"renderer.js",
"styles.css",
"visitor.py",
"download.py"
],
"dmg": {
"contents": [
{
"x": 110,
"y": 150
},
{
"x": 240,
"y": 150,
"type": "link",
"path": "/Applications"
}
]
},
"linux": {
"target": [
"AppImage",
"deb"
]
},
"win": {
"target": "squirrel",
"icon": "build/icon.ico"
}
},
"dependencies": {
"csv-parse": "^2.5.0",
"electron-css": "^0.6.0",
"npm": "^6.1.0",
"python-shell": "^0.5.0",
},
"devDependencies": {
"electron": "^2.0.3",
"electron-builder": "^20.19.1"
}
}
PS: This is the electron-builder I am talking about https://github.com/electron-userland/electron-builder
回答1:
You need to specify them as follows:
"extraFiles": [
"from":"source path",
"to":"your destination"
]
if you want to put those files by creating directory then use extraResources
"extraResources": [
"from":"source path",
"to":"some directory name"
]
for more info refer here
来源:https://stackoverflow.com/questions/51182226/electron-builder-is-not-bundling-the-python-files