Comments (6)
It's required for webpack HMR, since import
is only allowed at the top level. Sadly System.import()
won't work there either because of how webpack parses require() statements in the HMR callback. Cheers!
from preact-boilerplate.
To clarify: require() is the only way to do this because it's the only way to obtain the updated module definition from webpack.
from preact-boilerplate.
You could have a simple express server with the webpack-dev-middleware and webpack-hot-middleware. That way you can use imports across the whole project.
Adding a simple express server means that server side rendering could be added with react-dom/preact-compat.
from preact-boilerplate.
That would not solve the issue. This is already using webpack-dev-middleware
- that's what powers webpack-dev-server
. webpack-hot-middleware
doesn't help here either - as stated in their readme, it's still up to the application to update in response to HMR.
Basically, something has to re-import the root module in order to re-render it. Can't do that with ES Modules.
For what it's worth though, I do want to get rid of the manual implementation (because I agree, it's awkward to have both types of imports in one file). I've been looking into making Preact work out-of-the-box with React Hot Loader, which would make all of the manual HMR stuff unnecessary.
from preact-boilerplate.
In my side project I'm using HMR with an express server in which I'm not using require at all. I'm not 100% sure how it works as I used a boilerplate and just tweaked it. I'll take a look at what I'm doing and see if I can come up with a viable solution. If I do find something, would it be okay to make a PR?
from preact-boilerplate.
Sure, but drop me a line first via Twitter or the Preact slack if you find something - want to make sure first. It's possible your setup is using HMR but not actually re-rendering components in response to HMR, or that it doesn't account for the root component changing.
from preact-boilerplate.
Related Issues (20)
- Help with config? HOT 4
- An in-range update of script-ext-html-webpack-plugin is breaking the build 🚨 HOT 1
- An in-range update of eslint-plugin-react is breaking the build 🚨 HOT 2
- An in-range update of copy-webpack-plugin is breaking the build 🚨 HOT 2
- An in-range update of promise-polyfill is breaking the build 🚨 HOT 1
- await needed in router tests (app.test.js)? HOT 4
- An in-range update of css-loader is breaking the build 🚨 HOT 3
- An in-range update of serve is breaking the build 🚨 HOT 6
- An in-range update of postcss-loader is breaking the build 🚨 HOT 1
- Example of SW integration HOT 3
- Static HTML files? question HOT 1
- An in-range update of preact is breaking the build 🚨 HOT 2
- An in-range update of preact-router is breaking the build 🚨 HOT 1
- An in-range update of serve is breaking the build 🚨 HOT 1
- dependency bugs HOT 3
- requestAnimationFrame for HMR ? HOT 2
- unexpected token { HOT 1
- nrp run dev does not show latest changes HOT 1
- BrowserslistError: Unknown browser query `dead`
- Error when I try to install
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from preact-boilerplate.