0

I have a create-react-app and I'm trying to figure out how to get electron-packager to create an .exe using the production build. It keeps using the development folder in ./src

Running

electron-packager . --no-prune --ignore=/node_modules --ignore=/e2e --overwrite --ignore=/src

doesn't work. I also tried

electron-packager ./build --no-prune --ignore=/node_modules --ignore=/e2e --overwrite --ignore=/src

Here are the relevant entries in my package.json

{
    "homepage": "./",
    "main": "src/electron-entry.js",
    "build": {
        "target": "nsis",
        "dir": "./build"
    }
}

Here is my loadURL that points to the production build. In electron-entry.js. This works when I run in a dev environment.

new BrowserWindow(BrowserWindowProps).loadURL(url.format({
    pathname: path.join(__dirname, '/../build/index.html'),
    protocol: 'file:',
    slashes: true
}));

Is the data in electron-entry.js even relevant to the directory electron-packager uses?

4

1 回答 1

0

找到了解决方案。我将电子条目文件放入根目录并更改了loadURL以反映这一点。

let startUrl = process.env.ELECTRON_START_URL || url.format({
    pathname: path.join(__dirname, '/build/index.html'),
    protocol: 'file:',
    slashes: true
});
mainWindow.loadURL(startUrl);

更改了我的 package.json 以反映此更改:

{
  "main": "./electron-entry.js",
}

然后我跑了

electron-packager . --no-prune --ignore=/node_modules --ignore=/e2e --overwrite --ignore=/src

于 2018-04-12T19:02:50.093 回答