-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React 16 + HMR + Single Webpack + Reorganization #65
Conversation
TODO:
|
… into more-extensions
… into more-extensions
package.json
Outdated
"compile": "electron-webpack", | ||
"test": "cross-env NODE_ENV=test ./node_modules/.bin/jest", | ||
"test": "cross-env NODE_ENV=test jest", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? Why? This is not a good practice.
package.json
Outdated
@@ -6,7 +6,7 @@ | |||
"dev": "electron-webpack dev", | |||
"prod": "electron-webpack prod", | |||
"compile": "electron-webpack", | |||
"test": "cross-env NODE_ENV=test jest", | |||
"test": "cross-env NODE_ENV=test ./node_modules/.bin/jest", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay this is better then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just trying differnet things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ook <3
Ho boy so this is gonna be a lot.
Main Rational
We need to be able to reuse code from
lib
in both the renderer and main process. To do that we'll need to be able to accommodate both styles of module loading:Renderer Style imports
Main (or node) style imports
On the frontend
import
statements work because of our webpack config. We needed to have webpack for React and happened to get import statements for free.THE PROBLEM
Some modules should be available to both the renderer AND main. However, if they use
import
statements anywhere in their code (even in things they load in) they will completely fail in the main process.So for example, let's say we have this import-style module:
Then, later we would like to use it in the main process somewhere like so:
This will produce an error that tells us it doesn't know what the
import
statement on the first line oflib/someImportStyleModule.js
is.The fix
With this problem, what we could do is add yet another webpack config to the project. This would mean yet another build command and run command to add to our... 😅 ever expanding selection:
Since that seemed like a nightmare that I don't think we want to go down, I looked for some better options and came across
electron-webpack
.Electron-webpack gives us existing webpack configs that we don't need to touch and use, similar to what I wanted sea-floor to be like. Except this one works <3
The changes
In order to use
electron-webpack
nicely, we had to do some reorganization and some rule changes.app
andlib
were combined intosrc/lib
,src/main
andsrc/renderer
.yarn
. It's faster and nicer anyway <3If you're not familiar with yarn, here's an overview:
Added side benefits
Electron-webpack also gave us some added side stuff when I set it up.