You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to webpack's documentation I just need to add new webpack.HotModuleReplacementPlugin() to plugins section (development.js) and run webpack-dev-server with --hot switch (development.server.js). But with that you see that HMR doesn't work properly. The whole page gets reloaded (HMR messages in console disappear).
Then you add --hot-only switch (development.server.js) for webpack-dev-server to not fall back to live reload. And see that it can't find hot-update.json file, whatever that may be:
That happens since it's asking for it your rails app (localhost:3000), not webpack-dev-server (localhost:8080). And the reason for that is, output.publicPath option is not set. It's set for webpack-dev-server, but not for webpack itself.
You add it to development.server.js (headers: {'Access-Control-Allow-Origin': 'http://localhost:3000'}), and check again. This time your site doesn't see your updates:
[HMR] Checking for updates on the server...
[HMR] Nothing hot updated.
And that has to do with extract-text-webpack-plugingnot meant to be used in development. So, you disable it (new ExtractTextPlugin({disable: env.NODE_ENV != 'production', filename: ...). Or this way. And now it sort of works, but you see:
in console. That's because <%= stylesheet_pack_tag 'application' %> in layout still tries to find extracted css file. But we no longer extract it in development env. And thus you end up with:
The one improvement you can make here is make use of css-hot-loader package. It allows not to disable extract-text-webpack-plugin in development environment.
The text was updated successfully, but these errors were encountered:
It'd be great to have at least some sort of description for making HMR work. Let me share what I did. Any criticism and suggestions are welcome.
tl;dr
detailed explanation
According to
webpack
's documentation I just need to addnew webpack.HotModuleReplacementPlugin()
toplugins
section (development.js
) and runwebpack-dev-server
with--hot
switch (development.server.js
). But with that you see that HMR doesn't work properly. The whole page gets reloaded (HMR messages in console disappear).Then you add
--hot-only
switch (development.server.js
) forwebpack-dev-server
to not fall back to live reload. And see that it can't findhot-update.json
file, whatever that may be:That happens since it's asking for it your
rails
app (localhost:3000
), notwebpack-dev-server
(localhost:8080
). And the reason for that is,output.publicPath
option is not set. It's set forwebpack-dev-server
, but not forwebpack
itself.The error gets triggered here. Since
$require$.p
is empty string. And$require$.p
is empty because it's basicallyoutput.publicPath
option.So, we add
output.publicPath
and the next thing you see iswebpack-dev-server
asking you to allow yourrails
app access towebpack-dev-server
:You add it to
development.server.js
(headers: {'Access-Control-Allow-Origin': 'http://localhost:3000'}
), and check again. This time your site doesn't see your updates:And that has to do with
extract-text-webpack-pluging
not meant to be used in development. So, you disable it (new ExtractTextPlugin({disable: env.NODE_ENV != 'production', filename: ...
). Or this way. And now it sort of works, but you see:in console. That's because
<%= stylesheet_pack_tag 'application' %>
in layout still tries to find extracted css file. But we no longer extract it in development env. And thus you end up with:The one improvement you can make here is make use of
css-hot-loader
package. It allows not to disableextract-text-webpack-plugin
in development environment.The text was updated successfully, but these errors were encountered: