electron-builder not working for production due to path











up vote
0
down vote

favorite












everyone



I created a React app in order to build an electron app. I'm trying to use electron-builder to create the installers. I'm working on Ubuntu trying to generate a .deb.



I didn't use create-react-app, I used a boilerplate I already had, but I don't know if this is the problem.



I can make it work as long as I edit the index.html the webpack generates in the build folder. I have to change the path to main.css and build.js from /main.css and /build.js to ./main.css and ./build.js.



I read that I have to use the "homepage" property in package.json, but it's not working, seems to be ignored.



My folder structure is like:



package.json
src/
config/
main_electron_file.js
build/ #generated by webpack when I run the 'build:prd' command
public/ #empty


package.json



{
"name": "frontend",
"version": "1.0.0",
"description": "",
"main": "./main_electron_file.js",
"scripts": {
"dev": "./node_modules/.bin/webpack-dev-server --config ./config/webpack.config.dev.js --mode development --open --hot",
"build:prd": "./node_modules/webpack/bin/webpack.js --mode production --config ./config/webpack.config.prd.js --env.NODE_ENV=production --progress",
"electron": "electron .",
"start": "npm run dev && npm run electron",
"start:dev": "ELECTRON_START_URL=http://localhost:3000 electron .",
"dist": "build"
},
"keywords": ,
"author": {
"name": "name",
"email": "email@mail.com"
},
"license": "ISC",
"dependencies": {
...
},
"devDependencies": {
...
},
"homepage": "./",
"build": {
"appId": "com.myself.myapp",
"linux": {
"target": [
"deb"
]
}
}
}


main_electron_file.js



// Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron');

const path = require('path');
const url = require('url');

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow

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

// Create the browser window.
mainWindow = new BrowserWindow({ width: 800, height: 600, resizeble: false });
mainWindow.setResizable(false);

// and load the index.html of the app.
// win.loadURL('http://localhost:3000');
mainWindow.loadURL(startUrl);

// Open the DevTools.
mainWindow.webContents.openDevTools()

// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.


By the way. I'm not building it. I'm running it pointing to the index.html in the dist, as I would do in production mode. So i'm running npm run build:prd and then npm run electron



ANy ideas how I could make this process automatic?










share|improve this question


























    up vote
    0
    down vote

    favorite












    everyone



    I created a React app in order to build an electron app. I'm trying to use electron-builder to create the installers. I'm working on Ubuntu trying to generate a .deb.



    I didn't use create-react-app, I used a boilerplate I already had, but I don't know if this is the problem.



    I can make it work as long as I edit the index.html the webpack generates in the build folder. I have to change the path to main.css and build.js from /main.css and /build.js to ./main.css and ./build.js.



    I read that I have to use the "homepage" property in package.json, but it's not working, seems to be ignored.



    My folder structure is like:



    package.json
    src/
    config/
    main_electron_file.js
    build/ #generated by webpack when I run the 'build:prd' command
    public/ #empty


    package.json



    {
    "name": "frontend",
    "version": "1.0.0",
    "description": "",
    "main": "./main_electron_file.js",
    "scripts": {
    "dev": "./node_modules/.bin/webpack-dev-server --config ./config/webpack.config.dev.js --mode development --open --hot",
    "build:prd": "./node_modules/webpack/bin/webpack.js --mode production --config ./config/webpack.config.prd.js --env.NODE_ENV=production --progress",
    "electron": "electron .",
    "start": "npm run dev && npm run electron",
    "start:dev": "ELECTRON_START_URL=http://localhost:3000 electron .",
    "dist": "build"
    },
    "keywords": ,
    "author": {
    "name": "name",
    "email": "email@mail.com"
    },
    "license": "ISC",
    "dependencies": {
    ...
    },
    "devDependencies": {
    ...
    },
    "homepage": "./",
    "build": {
    "appId": "com.myself.myapp",
    "linux": {
    "target": [
    "deb"
    ]
    }
    }
    }


    main_electron_file.js



    // Modules to control application life and create native browser window
    const { app, BrowserWindow } = require('electron');

    const path = require('path');
    const url = require('url');

    // Keep a global reference of the window object, if you don't, the window will
    // be closed automatically when the JavaScript object is garbage collected.
    let mainWindow

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

    // Create the browser window.
    mainWindow = new BrowserWindow({ width: 800, height: 600, resizeble: false });
    mainWindow.setResizable(false);

    // and load the index.html of the app.
    // win.loadURL('http://localhost:3000');
    mainWindow.loadURL(startUrl);

    // Open the DevTools.
    mainWindow.webContents.openDevTools()

    // Emitted when the window is closed.
    mainWindow.on('closed', function () {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null
    })
    }

    // This method will be called when Electron has finished
    // initialization and is ready to create browser windows.
    // Some APIs can only be used after this event occurs.
    app.on('ready', createWindow)

    // Quit when all windows are closed.
    app.on('window-all-closed', function () {
    // On OS X it is common for applications and their menu bar
    // to stay active until the user quits explicitly with Cmd + Q
    if (process.platform !== 'darwin') {
    app.quit()
    }
    })

    app.on('activate', function () {
    // On OS X it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (mainWindow === null) {
    createWindow()
    }
    })

    // In this file you can include the rest of your app's specific main process
    // code. You can also put them in separate files and require them here.


    By the way. I'm not building it. I'm running it pointing to the index.html in the dist, as I would do in production mode. So i'm running npm run build:prd and then npm run electron



    ANy ideas how I could make this process automatic?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      everyone



      I created a React app in order to build an electron app. I'm trying to use electron-builder to create the installers. I'm working on Ubuntu trying to generate a .deb.



      I didn't use create-react-app, I used a boilerplate I already had, but I don't know if this is the problem.



      I can make it work as long as I edit the index.html the webpack generates in the build folder. I have to change the path to main.css and build.js from /main.css and /build.js to ./main.css and ./build.js.



      I read that I have to use the "homepage" property in package.json, but it's not working, seems to be ignored.



      My folder structure is like:



      package.json
      src/
      config/
      main_electron_file.js
      build/ #generated by webpack when I run the 'build:prd' command
      public/ #empty


      package.json



      {
      "name": "frontend",
      "version": "1.0.0",
      "description": "",
      "main": "./main_electron_file.js",
      "scripts": {
      "dev": "./node_modules/.bin/webpack-dev-server --config ./config/webpack.config.dev.js --mode development --open --hot",
      "build:prd": "./node_modules/webpack/bin/webpack.js --mode production --config ./config/webpack.config.prd.js --env.NODE_ENV=production --progress",
      "electron": "electron .",
      "start": "npm run dev && npm run electron",
      "start:dev": "ELECTRON_START_URL=http://localhost:3000 electron .",
      "dist": "build"
      },
      "keywords": ,
      "author": {
      "name": "name",
      "email": "email@mail.com"
      },
      "license": "ISC",
      "dependencies": {
      ...
      },
      "devDependencies": {
      ...
      },
      "homepage": "./",
      "build": {
      "appId": "com.myself.myapp",
      "linux": {
      "target": [
      "deb"
      ]
      }
      }
      }


      main_electron_file.js



      // Modules to control application life and create native browser window
      const { app, BrowserWindow } = require('electron');

      const path = require('path');
      const url = require('url');

      // Keep a global reference of the window object, if you don't, the window will
      // be closed automatically when the JavaScript object is garbage collected.
      let mainWindow

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

      // Create the browser window.
      mainWindow = new BrowserWindow({ width: 800, height: 600, resizeble: false });
      mainWindow.setResizable(false);

      // and load the index.html of the app.
      // win.loadURL('http://localhost:3000');
      mainWindow.loadURL(startUrl);

      // Open the DevTools.
      mainWindow.webContents.openDevTools()

      // Emitted when the window is closed.
      mainWindow.on('closed', function () {
      // Dereference the window object, usually you would store windows
      // in an array if your app supports multi windows, this is the time
      // when you should delete the corresponding element.
      mainWindow = null
      })
      }

      // This method will be called when Electron has finished
      // initialization and is ready to create browser windows.
      // Some APIs can only be used after this event occurs.
      app.on('ready', createWindow)

      // Quit when all windows are closed.
      app.on('window-all-closed', function () {
      // On OS X it is common for applications and their menu bar
      // to stay active until the user quits explicitly with Cmd + Q
      if (process.platform !== 'darwin') {
      app.quit()
      }
      })

      app.on('activate', function () {
      // On OS X it's common to re-create a window in the app when the
      // dock icon is clicked and there are no other windows open.
      if (mainWindow === null) {
      createWindow()
      }
      })

      // In this file you can include the rest of your app's specific main process
      // code. You can also put them in separate files and require them here.


      By the way. I'm not building it. I'm running it pointing to the index.html in the dist, as I would do in production mode. So i'm running npm run build:prd and then npm run electron



      ANy ideas how I could make this process automatic?










      share|improve this question













      everyone



      I created a React app in order to build an electron app. I'm trying to use electron-builder to create the installers. I'm working on Ubuntu trying to generate a .deb.



      I didn't use create-react-app, I used a boilerplate I already had, but I don't know if this is the problem.



      I can make it work as long as I edit the index.html the webpack generates in the build folder. I have to change the path to main.css and build.js from /main.css and /build.js to ./main.css and ./build.js.



      I read that I have to use the "homepage" property in package.json, but it's not working, seems to be ignored.



      My folder structure is like:



      package.json
      src/
      config/
      main_electron_file.js
      build/ #generated by webpack when I run the 'build:prd' command
      public/ #empty


      package.json



      {
      "name": "frontend",
      "version": "1.0.0",
      "description": "",
      "main": "./main_electron_file.js",
      "scripts": {
      "dev": "./node_modules/.bin/webpack-dev-server --config ./config/webpack.config.dev.js --mode development --open --hot",
      "build:prd": "./node_modules/webpack/bin/webpack.js --mode production --config ./config/webpack.config.prd.js --env.NODE_ENV=production --progress",
      "electron": "electron .",
      "start": "npm run dev && npm run electron",
      "start:dev": "ELECTRON_START_URL=http://localhost:3000 electron .",
      "dist": "build"
      },
      "keywords": ,
      "author": {
      "name": "name",
      "email": "email@mail.com"
      },
      "license": "ISC",
      "dependencies": {
      ...
      },
      "devDependencies": {
      ...
      },
      "homepage": "./",
      "build": {
      "appId": "com.myself.myapp",
      "linux": {
      "target": [
      "deb"
      ]
      }
      }
      }


      main_electron_file.js



      // Modules to control application life and create native browser window
      const { app, BrowserWindow } = require('electron');

      const path = require('path');
      const url = require('url');

      // Keep a global reference of the window object, if you don't, the window will
      // be closed automatically when the JavaScript object is garbage collected.
      let mainWindow

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

      // Create the browser window.
      mainWindow = new BrowserWindow({ width: 800, height: 600, resizeble: false });
      mainWindow.setResizable(false);

      // and load the index.html of the app.
      // win.loadURL('http://localhost:3000');
      mainWindow.loadURL(startUrl);

      // Open the DevTools.
      mainWindow.webContents.openDevTools()

      // Emitted when the window is closed.
      mainWindow.on('closed', function () {
      // Dereference the window object, usually you would store windows
      // in an array if your app supports multi windows, this is the time
      // when you should delete the corresponding element.
      mainWindow = null
      })
      }

      // This method will be called when Electron has finished
      // initialization and is ready to create browser windows.
      // Some APIs can only be used after this event occurs.
      app.on('ready', createWindow)

      // Quit when all windows are closed.
      app.on('window-all-closed', function () {
      // On OS X it is common for applications and their menu bar
      // to stay active until the user quits explicitly with Cmd + Q
      if (process.platform !== 'darwin') {
      app.quit()
      }
      })

      app.on('activate', function () {
      // On OS X it's common to re-create a window in the app when the
      // dock icon is clicked and there are no other windows open.
      if (mainWindow === null) {
      createWindow()
      }
      })

      // In this file you can include the rest of your app's specific main process
      // code. You can also put them in separate files and require them here.


      By the way. I'm not building it. I'm running it pointing to the index.html in the dist, as I would do in production mode. So i'm running npm run build:prd and then npm run electron



      ANy ideas how I could make this process automatic?







      reactjs webpack electron electron-builder






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 1:32









      Victor Ferreira

      1,80733661




      1,80733661
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Please try adding this line in your index.html



          <base href="./">


          And your main.css and build.js directory should be set relative to your index.html in build folder






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422717%2felectron-builder-not-working-for-production-due-to-path%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Please try adding this line in your index.html



            <base href="./">


            And your main.css and build.js directory should be set relative to your index.html in build folder






            share|improve this answer

























              up vote
              0
              down vote













              Please try adding this line in your index.html



              <base href="./">


              And your main.css and build.js directory should be set relative to your index.html in build folder






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Please try adding this line in your index.html



                <base href="./">


                And your main.css and build.js directory should be set relative to your index.html in build folder






                share|improve this answer












                Please try adding this line in your index.html



                <base href="./">


                And your main.css and build.js directory should be set relative to your index.html in build folder







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 at 15:32









                carlokid

                574




                574






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422717%2felectron-builder-not-working-for-production-due-to-path%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    What visual should I use to simply compare current year value vs last year in Power BI desktop

                    How to ignore python UserWarning in pytest?

                    Alexandru Averescu