electron-userland / electron-webpack

Scripts and configurations to compile Electron applications using webpack
https://webpack.electron.build/
903 stars 170 forks source link

Allow entry points to be other file types #225

Open cmeeren opened 5 years ago

cmeeren commented 5 years ago

I am using fable-loader to load .fs and .fsproj files. My entry point is an fsproj file. Unfortnately, I only get the following error when running electron-webpack dev:

Error: Cannot find entry file src\Main\index.ts (or main.ts, or app.ts, or index.js, or main.js, or app.js)

It seems the files to look for is hardcoded. This seems to put a complete stop to using arbitrary loaders for entry points in other formats/languages such as F# using fable-loader. (Sorry if this is nonsense; I'm very new to JS and webpack.)

Would it be possible to add support for specifying entry points of arbitrary names/extensions using configured loaders?

cmeeren commented 5 years ago

I can confirm that with a webpack.additions.main.js like

var path = require("path");

module.exports = {
  entry: path.join(__dirname, "src/Main/Main.fsproj"),
  module: {
    rules: [
      {
        test: /\.fs(x|proj)?$/,
        use: {
          loader: "fable-loader"
        }
      }
    ]
  }
}

I can successfully run the app as long as I edit node_modules/electron-webpack/out/main.js to include the relevant extensions and names in the two lists. (Sorry, I don't know enough about JS yet to set up electron-webpack for local development. I just did a proof-of-concept by editing the source directly in the node_modules folder.)

Again, I suggest that you allow specifying an arbitrary entry point file, which would solve this once and for all.

cician commented 5 years ago

I'd like to use electron-webpack with F#/Fable too and encountered the same issue. I wonder what would be the recommended way going forward, should we write an electron-webpack plugin like the one for typescript? Seems a bit superfluous to me since fable-loader already does all the necessary work to bootstrap F# applications in standard nodejs scenario just fine.

cmeeren commented 5 years ago

@cician if you want a quick fix, take a look at https://github.com/cmeeren/fable-elmish-electron-demo. In build.fsx, there is a target that replaces a couple of lines in node_modules/electron-webpack/out/main.js to make electron-webpack load the fs/fsproj files for the main and renderer processes.

That said, I hope electron-webpack will allow specifying arbitrary entry points so that this can work without flaky patching.

cician commented 5 years ago

@cician if you want a quick fix, take a look at https://github.com/cmeeren/fable-elmish-electron-demo. In build.fsx, there is a target that replaces a couple of lines in node_modules/electron-webpack/out/main.js to make electron-webpack load the fs/fsproj files for the main and renderer processes.

That said, I hope electron-webpack will allow specifying arbitrary entry points so that this can work without flaky patching.

Thank you. I've managed to make it run by following your demo project, but with a slightly different workaround: I Just created an empty main.js file to fool electron-webpack.

cmeeren commented 5 years ago

@cician Brilliant, thanks! Works great. Will update the repo with your workaround. Quite a bit simpler than mine.

mjashanks commented 5 years ago

Hi there, I just created a PR that should help with this: #291