Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to improve webpack performance?

Tags:

I recently switched from browserify to webpack and the build time jumped from 4s to 16s on (2014 MBP). I understand webpack does alot more than browserify but i shouldn't take that long. My build process is fairly simple. Are there any tips or options to improve my build time?

var webpackOptions = {   cache : true,   output: {     filename: '[name].js',   },   module: {     loaders: [       { test: /\.js$/, loader: 'jsx-loader' },       { test: /\.css$/, loader: "style!css" }     ]   }, };   gulp.task('buildJs', function(){      multipipe(       gulp.src(jsSrcPath),       named(),       webpack(webpackOptions),       uglify(),       gulp.dest(jsDestPath)     ).on('error', function(error){       console.log(error)     }); }); 
like image 569
dpham Avatar asked Dec 10 '14 23:12

dpham


People also ask

Why is webpack so slow?

Over the past eight years, webpack has become increasingly powerful. However, due to the additional packaging process, the building speed is getting slower as the project grows. As a result, each startup takes dozens of seconds (or minutes), followed by a round of build optimization.

What is optimization in webpack?

Tells webpack to determine and flag chunks which are subsets of other chunks in a way that subsets don't have to be loaded when the bigger chunk has been already loaded. By default optimization. flagIncludedChunks is enabled in production mode and disabled elsewise. webpack.config.js module.

How long should a webpack build take?

We use babel and TailwindCSS. Using simple methods, I discovered that CSS and JS take about the same time to build. Benchmark: Webpack build took 64 seconds, whole build took 91 seconds.


1 Answers

You should set include paths for your loaders. Example:

{ test: /\.js$/, loader: 'jsx-loader', include: jsSrcPath } 

Consider doing the same for that css case.

In my experience this can give massive gains as it doesn't have to traverse through node_modules anymore. Alternatively you could exclude node_modules but I find it neater just to set up that include. It gets more complicated if you are requiring content out of the include path, though.

Docs for include/exclude

like image 77
Juho Vepsäläinen Avatar answered Oct 18 '22 07:10

Juho Vepsäläinen