saltyshiomix / nextron

⚡ Next.js + Electron ⚡
https://npm.im/nextron
MIT License
3.97k stars 229 forks source link

consider option for naming background.js to something else #50

Closed gautamsi closed 5 years ago

gautamsi commented 5 years ago

is it possible to use app/background.js (in package.json) to something else? I saw build directory name to be nextron, seems like that has been renamed to app any config option?

gautamsi commented 5 years ago

I was able to achieve like this

const cwd = process.cwd();
const { resolve } = require("path");

module.exports = {
  webpack: (defaultConfig, env) => Object.assign(defaultConfig, {
    entry: {
      background: "./main/electron.ts",
    },
    output: {
      ...defaultConfig.output,
      filename: "electron.js",
      path: resolve(cwd, "electron"),
    }
  }),
};

not sure if that has any consequence to production build, will figure out :)

saltyshiomix commented 5 years ago

Hi @gautamsi

Thank you for your questions!

It is not possible to rename app/background.js because we run electron . when development mode.

  1. $ electron . (run electron with the current directory)
  2. electron analyzes ./package.json#main
    1. package.json main field must be one of these
    2. index.js (recommended by electron)
    3. app/background.js (the compatibility for electron-builder's default source directory)

We adopt the app/background.js way because of simple directory structures. (And because of the existence of apps based on source compiling like Next.js and typescript.)

If you use JavaScript only, the structure of just two files index.js and index.html is the simplest solution.

saltyshiomix commented 5 years ago

But if you have any another solutions, please send a PR at any time!

saltyshiomix commented 5 years ago

@gautamsi

If you have any troubles, feel free to issue me up again :)