electron-userland / electron-userland/electron-webpack

HMR for main process does not work if adding entry to webpack.additions.main.js

Open
#303 17 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
902
Forks
168
PR merge metrics
No merged PRs in 30d

Description

Based on known good [electron-webpack-quick-start](https://github.com/electron-userland/electron-webpack-quick-start) (main process HMR works fine from the get-go, app restarts as expected when editing `main/index.js`):

Add `webpack.additions.main.js` with the following:

```js
var path = require("path");

module.exports = {
entry: path.join(__dirname, "src/main/index.js"),
}
```

Add the following to `package.json`:

```json
"electronWebpack": {
"main": {
"webpackConfig": "webpack.additions.main.js"
}
},
```

Now the app is **not** restarted when making changes to `main/index.js`. (The app otherwise works identically.)

I would expect main process HMR to work correctly even though I explicitly specify the entry point as above.

### Further information, in case it's relevant

Here is some console output when editing `main/index.js` without the extra config above (i.e. when everything works correctly):

```
┏ Main -----------------------

Hash: 2286fcb35f1542ca30fd
Version: webpack 4.35.0
Time: 30ms
Built at: 2019-07-08 3:49:40 PM
Asset Size Chunks Chunk Names
701bc5d738c52096d90b.hot-update.json 46 bytes [emitted]
main.701bc5d738c52096d90b.hot-update.js 7.05 KiB main [emitted] main
main.js 41.6 KiB main [emitted] main
Entrypoint main = main.js main.701bc5d738c52096d90b.hot-update.js
[0] multi ./node_modules/electron-webpack/out/electron-main-hmr/main-hmr ./src/main/index.js 40 bytes {main}
[./node_modules/electron-webpack/out/electron-main-hmr/main-hmr.js] 582 bytes {main} [built]
[./src/main/index.js] 1.41 KiB {main} [built]
[electron] external "electron" 42 bytes {main}
[electron-webpack/out/electron-main-hmr/HmrClient] external "electron-webpack/out/electron-main-hmr/HmrClient" 42 bytes {main}
[path] external "path" 42 bytes {main}
[source-map-support/source-map-support.js] external "source-map-support/source-map-support.js" 42 bytes {main}
[url] external "url" 42 bytes {main}

┗ ----------------------------
┏ Electron -------------------

[HMR] Error: Aborted because ./src/main/index.js is not accepted
Update propagation: ./src/main/index.js -> 0
at hotApply (C:\Users\Christer\Source\Repos\electron-webpack-quick-start\dist\main\main.js:453:30)
at C:\Users\Christer\Source\Repos\electron-webpack-quick-start\dist\main\main.js:291:22
[HMR] Cannot apply update. Need to do a full reload - application will be restarted

┗ ----------------------------
```

Here is the corresponding output with the configuration above (i.e. when HMR does not work):

```
┏ Main -----------------------

Hash: b61034546bbd4573c8db
Version: webpack 4.35.0
Time: 30ms
Built at: 2019-07-08 3:48:47 PM
Asset Size Chunks Chunk Names
57a1b38f9d575b98ce49.hot-update.json 46 bytes [emitted]
main.57a1b38f9d575b98ce49.hot-update.js 7.06 KiB main [emitted] main
main.js 36.3 KiB main [emitted] main
Entrypoint main = main.js main.57a1b38f9d575b98ce49.hot-update.js
[./src/main/index.js] 1.41 KiB {main} [built]
[electron] external "electron" 42 bytes {main}
[path] external "path" 42 bytes {main}
[url] external "url" 42 bytes {main}

┗ ----------------------------
```

I'm on Windows.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.