A loop webpack packages a project to different locations at the same time
let num
(new Array(num)),map((v, k) = {
let start = +new Date()
webpack(webpackConfig, () => {
console.log(`time:${+new Date() - start} ms)
})
})
time:5232ms
time:9212ms
time:9332ms
time:40212ms
time:40342ms
...
time: 4xxxxms
It doesn’t seem to be parallel in the true sense. It will wait until all webpack is fully executed before returning together
The expected effect is whoever builds it first will return it first, not together
Is this related to the single thread of nodejs?
Later, I used the parallel-webpack library, modified the source code, and printed the then return time of each promise. The results were similar, help
Nodejs execution is single-threaded, but your results are related to the way you write it.
You can try the following two solutions, the second of which can achieve true parallelism
1: Write each webpack task construction method in the loop to asynchronously, such as setTimeOut.
2: Start multiple node processes and execute webpack build on each process