javascript - webpack parallel (concurrent) packaging problem
扔个三星炸死你
扔个三星炸死你 2017-07-05 10:43:10
0
1
766

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)
  })
})
  • num = 1

 time:5232ms
  • num = 2

time:9212ms
time:9332ms
  • ...

  • num = 30

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

扔个三星炸死你
扔个三星炸死你

reply all(1)
曾经蜡笔没有小新

Nodejs execution is single-threaded, but your results are related to the way you write it.

The expected effect is who builds it first and returns it first, not together

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template