As mentioned in Webpack docs and many information that introducing how to improve webpack build speed, thread-loader can obviously improve the build speed of babel-loader.
But when I try it in my project, it seems like that thread-loader does not bring any optimization for babel-loader.
I use speed-measure-webpack-plugin to measure build speed, and there are the code and result of my test.
my device: Macbook Pro (15-inch, 2018, 6-core, 12-thread)
version information:
{ "webpack": "^4.41.2", "thread-loader": "^3.0.1", "babel-loader": "^8.2.2", "webpack-preprocessor-loader": "^1.1.3", }
Before using thread-loader for babel-loader, code of webpack.config.js:
// thread-loader rule: { test: /\.(jsx?)$/, exclude: [ /node_modules/, ], use: [ { loader: 'babel-loader', options: { babelrc: true, cacheDirectory: true, rootMode: 'upward', } }, { loader: 'webpack-preprocessor-loader', options: { params: env } }] }
Time cost:
SMP ⏱ Loaders thread-loader, and babel-loader, and webpack-preprocessor-loader took 15.71 secs module count = 315
After:
// thread-loader warmup: const threadLoader = require('thread-loader'); const threadLoaderOptions = { poolTimeout: 2000, name: 'thread-loader-for-babel' } threadLoader.warmup(threadLoaderOptions, [ 'webpack-preprocessor-loader', 'babel-loader' ]); // thread-loader rule: { test: /\.(jsx?)$/, exclude: [ /node_modules/, ], use: [ { loader: 'thread-loader', options: threadLoaderOptions }, { loader: 'babel-loader', options: { babelrc: true, cacheDirectory: true, rootMode: 'upward', } }, { loader: 'webpack-preprocessor-loader', options: { params: env } }] }
Time cost:
SMP ⏱ Loaders thread-loader, and babel-loader, and webpack-preprocessor-loader took 14.64 secs module count = 313
So, is there something wrong? or if this is reasonable, then why?
thanks in advance. :)
https://stackoverflow.com/questions/66885029/webpack4-thread-loader-bring-little-optimization-for-babel-loader-is-something March 31, 2021 at 05:28PM
没有评论:
发表评论