Comments (9)
https://github.com/webpack/enhanced-require/wiki/HCR-Spec
from webpack.
Interesting. I am using the LiveReload app, which does full page refresh operations a lot, but that doesn't bother me.
I am also using yeoman
and angular.js
, which can LiveReload my client, but I haven't patched-in my custom Express server yet. I also haven't experimented with your grunt task to automate my webpack
step, yet.
Problems:
-
When to check?
Most other livereload-like frameworks & tools bundle a websocket server, just to emit events when source changes. That seems like a pretty big dependency to add to Webpack, but polling for changes seems like an outdated solution. What do you think? You said you have a prototype version, how did you implement it there?
from webpack.
The "prototype" is [email protected]
and only work on node.js, where I offer FileWatchers (watch: true
) or manual checking (.check(cb)
).
For webpack I plan to offer polling (every 10 minutes in production should be not problem, an update is not so important) and manual checking (so you could send a event if you have already some kind of bidirectional connection).
The grunt task does nothing special. It just runs webpack. (grunt's watch task is worse than webpack's)
Full page refreshing is already availible through the webpack-dev-server
.
The impl plan is to emit special update files to the output directory, which contain all info regarding the update. There will be one main update file <old-hash>.update.js
and updates for the chunks <x>.<old-hash>.update.js
. Only modules that were updated are contained in these packages and the main file contains info about the new hash and existing update chunks.
The client can check existance of the main update file and download it. Than it can download the needed update chunks. When this is finished an update is availible and can be applied. If it can't be applied the app may display some info to do a whole page refresh.
To create these update files webpack need to know old module ids, old content hashes and the old bundle hash. So we need to use a hot reploading file which stores the info (--hot <file>
, { hot: <file> }
).
from webpack.
This feature is really crazy ^^
from webpack.
Yes it's crazy...
Here is more explanation:
All goals above have been reached.
Only modules (or module chains) which have opt-it (using the module API) can be replaced. An update will abort if any updated module havn't opt-in.
One can use the management API to start an update: module.hot.check(function(err, renewedModules) { /* ... */ });
If no update found renewedModules === null
.
Elsewise it will download hot update chunks for each loaded chunk. After the update have been downloaded, the hot replacement code will determine modules that will be renewed. Then:
- the old modules are disposed,
- the new code is installed,
- the accept handlers are called, and
- the self accepted modules are required.
API: https://github.com/webpack/docs/wiki/hot-code-replacement
It must be globally enabled with --hot
/ options.hot = true
.
If one don't write own management api code, one can use prepared code in the webpack/hot folder:
webpack/hot/dev-server
for the webpack-dev-server.
webpack/hot/poll
uses polling to find a update. (poll?10000
to specify a interval in ms)
Simple add it as entry:
module.exports = {
entry: ["webpack/hot/poll?600000", "./entry.js"]
// ...
};
webpack "webpack/hot/poll?600000" ./entry.js bundle.js --hot --records-path records.json
The style-loader
and mocha-loader
automatically generate hot-replaceable code.
So a stylesheet can be changed without a full page refresh and tests with changed dependencies rerun.
TODOs:
- do not download empty update chunks
from webpack.
so integrated in my app at the page router with 10 LOC... App can update itself without full page refresh...
Thanks to @Phoscur for proposing the best feature ever! 😄
from webpack.
added a demo to http://webpack.github.io/example-app/
there are 2 updates.... you can apply them with the two buttons on the right.
from webpack.
Here is a graphical example:
Compile time
Left: first compilation
module 4 changed: async require to module 10 removed
module 9 changed: normal require to module 12 added
Right: second compilation including Hot Update Chunks
Runtime
Assuming module 4 accepts itself and module 2 accepts module 3.
- Disposing modules: 3, 4, 5, 6, 8, 9, 10, 11
- Calling accept handler in module 2 (accepting module 3)
- Require self-accepted module 4
from webpack.
Thank you for doing this.
from webpack.
Related Issues (20)
- Module Federation - Some chunks are not loaded when navigating from the Remote module to the Host module
- failed to import ffmpeg-core.js HOT 1
- Webpack 5 doesnt generate the chunks of imports HOT 1
- Error: Cannot find module 'webpack-cli/package.json' HOT 2
- Unable to bust cache of module federation remotes....
- Re-exported Ant Design components don't have same style with the original components
- failed to import ffmpeg-core.js HOT 3
- DllPlugin: When processing multiple chunks, does the `path` option must have a string template?
- Webpack BannerPlugin with `raw` option should put `use strict` on the very first line HOT 10
- After webpack 5 migration not able to use local packages in a mono repo
- 95% emitting emit phase takes much longer in Node >=16
- Plugin apply not working for multi compiler HOT 2
- packages/tailwindcss/src/compile.ts HOT 1
- Current error handling mainly involves calling the `onInvalidCandidate` callback function to handle invalid candidates, and printing corresponding error messages to the console.
- [5.91.0] "Fixed fs types" breaks `outputFileSystem` compatibility with `memfs` HOT 6
- Using `[name]` within `output.library`, the correct value isn't utilized in the source map namespace HOT 1
- Not found node_modules/@angular/common/bundles/common-http.umd.js
- webpack5.90.0 Modifying files in the node_modules directory (local component library) cannot trigger hot updates HOT 1
- Delete this. HOT 1
- how to make webpack recompile on dev mode with cache on? HOT 1
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 webpack.