search

Home  >  Q&A  >  body text

javascript - webpack parallel (concurrent) packaging problem

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

扔个三星炸死你扔个三星炸死你2741 days ago803

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-07-05 10:45:10

    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

    reply
    0
  • Cancelreply