Repository navigation
Closed
Description
Originally posted this issue on webpack-dev-server's repo, but was told nearly all of HMR is handled by Webpack itself, so I am moving that issue over here.
- Operating System: Mac OS High Sierra
- Node Version: 8.10.0
- NPM Version: 5.6.0
- webpack Version: 4.1.1
- webpack-dev-server Version: 3.1.1
- This is a bug
- This is a modification request
Code
Note that the webpack file I posted isn't exactly what we have, but anything removed was just company info, me merging a common webpack file with our dev one to produce a single code snippet, and removing some unrelated/redundant info (e.g. multiple templates with similar content).
// webpack.config.js
const webpack = require('webpack');
const merge = require('webpack-merge');
const config = require('./webpack.common.config.js');
const Jarvis = require('webpack-jarvis');
module.exports = merge(config, {
mode: 'development',
devtool: 'cheap-module-eval-source-map',
output: {
publicPath: '/',
filename: '[name]-[hash].js',
crossOriginLoading: 'anonymous',
chunkFilename: '[name]-[hash].js'
},
optimization: {
noEmitOnErrors: true,
namedModules: true,
},
plugins: [
new CopyWebpackPlugin([{
from: 'app/assets/images/favicon/',
to: 'favicon/',
}]),
new CopyWebpackPlugin([{
from: 'app/assets/images/square/logo.png',
to: 'logo.png',
}]),
new ExtractTextPlugin({
filename: '[name]-styles-[contenthash].css',
allChunks: true,
}),
new DeterministicHash(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new HtmlWebpackPlugin({
template: 'templates/index.ejs',
filename: 'index.html',
inject: false,
chunks: ['common', 'main'],
appleTouchIconSizes: [57, 72, 114, 120, 144, 152],
}),
new Jarvis({port: 7003}),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
_DEVELOPMENT_: true,
})
],
module: {
rules: [
{
test: /\.(otf|ttf|woff|woff2|png|jpg|svg|mp3|wav|aff|dic)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'assets/[name]-[sha1:hash:hex:8].[ext]'
},
},
]
},
{
test: /\.s?css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: () => [
require('precss'),
require('autoprefixer'),
]
}
},
'sass-loader'
]
}),
},
{
test: /\.jsx?$/,
use: ['babel-loader'],
},
]
},
entry: {
main: [
'babel-polyfill',
'react-hot-loader/patch',
'webpack/hot/only-dev-server',
'webpack-dev-server/client?https://0.0.0.0:7001',
'./app/main.js',
],
}
}); // dev-server.js
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.devconfig');
const ssl = require('./devssl');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
headers: {'Access-Control-Allow-Origin': '*'},
hot: true,
https: true,
clientLogLevel: 'error',
cert: ssl.cert,
overlay: true,
key: ssl.key,
historyApiFallback: true,
disableHostCheck: true,
watchOptions: {
ignored: /\/node_modules\/.*/,
},
stats: {
assets: false,
cached: false,
cachedAssets: false,
children: false,
chunks: false,
chunkModules: false,
chunkOrigins: false,
colors: true,
depth: false,
entrypoints: true,
excludeAssets: /app\/assets/,
hash: false,
maxModules: 15,
modules: false,
performance: true,
reasons: false,
source: false,
timings: true,
version: false,
warnings: true,
},
}).listen(7001, '0.0.0.0', function(err, result) {
console.log(`Serving chunks at path ${config.output.publicPath}`);
});Expected Behavior
Similar, if not faster HMR
Actual Behavior
Hot reload time increased from ~5s to ~10s when upgrading from Webpack 3 to Webpack 4.
For Bugs; How can we reproduce the behavior?
Unsure if it reproduces in every case, but in our case we have a large webapp that spits out multiple entry points, with sass processing, along with a lot of other webpack features.
Reacted by Pierre Poupin, Dan Gornstein, Jorge Barnaby, Nikhil Daga, Javier Perez, Chris Watts, Dylan Greene, Mark Penner, maple, Mitchell Gerber and 56 more
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Priority
None yet
Activity
dylang commentedon Mar 16, 2018
Have you tried your Webpack 4 changes in an older version of node, say 8.9.4? For us it makes it fast again.
sokra commentedon Mar 17, 2018
cc @bmeurer node 8.10 includes a V8 6.2 upgrade.
bmeurer commentedon Mar 19, 2018
Interesting. Any idea what it could be related to? 6.2 is a pretty massive update (performance-wise).
cc @hashseed @psmarshall @mathiasbynens
hashseed commentedon Mar 19, 2018
Would you be willing to bisect the V8 change that caused this regression? I have some instructions here.
drewjenkins commentedon Mar 19, 2018
For reference, I did some benchmarks comparing various nodes with various webpack versions. I don't claim to be an expert, I just thought it may be helpful to have more information.
For my test, I just added and removed the string 'test' to a React component 10 times, saving between each addition/removal. These numbers should be taken with a grain of salt since when upgrading from Webpack 3 to Webpack 4, we had to change our process slightly, however the overarching trend seems clear. Node 8.10.0 definitely seems to be impacting the rebuild time, though Webpack 3->4 seems to be a larger cause of the increase.
Sojborg commentedon Apr 3, 2018
I get much worse build results after going from webpack 3 -> 4
Webpack 3.10.0 - Node 8.9.4
Build - 61 secs
Webpack 3.10.0 - Node 9.6.1
Build 65 secs
Webpack 4.4.1 - Node 8.9.4
Build 74 secs
Webpack 4.4.1 - Node 9.6.1
Build 106 secs
Are you guys looking into this decrease in performance from webpack 3 to 4?
montogeek commentedon Apr 4, 2018
@Sojborg What is your webpack configuration?
Sojborg commentedon Apr 4, 2018
I only opgrader webpack version i didn't change the config. So I still use the old plugin API could that affect performance?
zenkilies commentedon Apr 5, 2018
@Sojborg let try adding this line to the config:
malixsys commentedon Apr 10, 2018
Shouldn't you use
mini-css-extract-plugininstead ofExtractTextPlugin? 🤔p3x-robot commentedon Apr 18, 2018
I use development mode and it became a snail. 👎
alexander-akait commentedon Apr 18, 2018
@drewjenkins Can you create minimum reproducible test repo with same config for webpack@3 and webpack@4 when you have increase hmr time?
alexander-akait commentedon Apr 18, 2018
/cc @Sojborg @drewjenkins please read comment above
p3x-robot commentedon Apr 18, 2018
It is too hard to update everything, the downgrade is too expensive to play with this.
I did the same with UglifyJS3, i tried, UglifyJs2.2.something was 22 seconds, then first version 3 was 4 minutes 42 seconds, the in about 2 months, it became 44 seconds. It was ok, for building.
For me is the same:
webpack/webpack-dev-server#1346
In my code you can use I set development mode, here:
https://github.com/patrikx3/corifeus-builder-angular/blob/master/src/config/webpack/angular/dev.js#L15
And execute here as the config is generated:
https://github.com/patrikx3/corifeus-builder-angular/blob/master/src/config/webpack/angular/common.js#L35
https://github.com/patrikx3/corifeus-builder-angular/blob/master/src/config/webpack/angular/common.js#L161
But I even did like this, if this is a mistake:
Building is about: 50 seconds
Changing 1 line takes about : 18 seconds
Well, actually I dont know, this is kind of ok (giving it is Typescript).
But I remember it was much faster (i see it is compiling something i have never changed), it was a jiffy to update. I dont know, maybe I am wrong, sorry.
birkir commentedon Apr 21, 2018
I traced my slowdown to the thread-loader... Either disable it or set its timeout to Infinity
34 remaining items
mran3 commentedon Dec 1, 2018
For my site which generates more than 40 files using htmlwebpack plugin, the comments of @aaronjensen and @edmorley had a big impact, as it was becoming impossible to work on the site, to install the beta you can use:
npm i --save-dev html-webpack-plugin@nextYounghun-Jung commentedon Dec 18, 2018
Guys.
I think key solution of this issue, devtool option.
I change 'inline-source-map' into 'cheap-module-eval-source-map' on devtool option, and
speed is faster from 15s to 2s.
thanks @voxmatt
you save my time.
cute-angelia commentedon Jan 3, 2019
Thanks @searene! the
webpack modeis very important option about webpack speedkelly-tock commentedon Jan 25, 2019
if you set anything in optimization in your config, does webpack merge it with defaults provided by 'development' mode?
olosegres commentedon Jan 31, 2019
Guys, this solves the problem! (at least for me)
It seems, that webpack 4 use inside CommonsChunkPlugin with new default options, so you should disable defaults.
kelly-tock commentedon Jan 31, 2019
We’ve gotten our rebuilds down to around 5 seconds on a large codebase.
salujaharkirat commentedon Feb 28, 2019
Setting mode to develop really increases the reload speed but I need to use
localhostas I have an environment map as follows:-Specifying development as mode was reloading the changes really fast but the functionality was breaking, as development app environment was returned instead of local.
Added following to solve the problem:-
illiatoka commentedon Sep 18, 2019
@voxmatt Oh man, you've saved my life, thanks a lot!
sibelius commentedon Mar 5, 2020
what is the proper version of
html-webpack-pluginto fix this?matheus1lva commentedon Mar 5, 2020
@sibelius see if https://github.com/styleguidist/mini-html-webpack-plugin helps with it!
alexander-akait commentedon Sep 2, 2020
I want to close this issue, for webpack@4 we did everything we could, also almost all loaders and plugins received updates and performance improvements, webpack@5 has more improvements and very fast, anyway if you faced with performance again (in webpack@5 too) please open new issue with reproducible test repo, thanks for using webpack, feel free to feedback
zerofirework commentedon Dec 16, 2021
Late to the party but I recently run into a similar issue. We end up finding that WEBPACK_DEV_SERVER env variable is no longer set in the new dev server (webpack/webpack-cli#1973). We use the variable to gate whether to run optimization and other production only configs. The performance is recovered after this is fixed.
Ryan-LT commentedon Sep 14, 2022
Scrolling through all replies, tried out many of them. This is the most effective one. Our project hot loader speed has decreased from 10s to just 200ms. Crazy!
jetani-ravi commentedon Jan 11, 2024
This works for me
"mode": process.env.NODE_ENV === "production" ? "production" : "development",