Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

435
Views
How can I get all module dependencies of each entry in webpack5, including the ones that are external

My appeal is, some dependencies in my project have been external, and these dependencies are shared by multiple entries. I want to count the external dependencies used by each entry

With webpack4:

function _getAllDeps(module) {
    const moduleRecord = {};
    const result = {};
    const _find = (module) => {
        if (!module || moduleRecord[module.request]) {
            return false;
        }
        moduleRecord[module.request] = true;
        if (module.dependencies && Array.isArray(module.dependencies)) {
            module.dependencies.forEach((dep) => {
                _find(dep.module);
                
                // all dependencies are there, and I can pick the 'externals' by `module.external`
                if (!(dep.module && dep.module.external)) {
                    return false;
                }
                const { request } = dep.module;
                result[request] = true;
            });
        }
    };
    _find(module);
    return Object.keys(result);
}

compiler.hooks.emit.tapAsync('xxxxx', (compilation, done) => {
    compilation.chunks.forEach((chunk) => {
        const actualDeps = _getAllDeps(chunk.entryModule)

        // Now, I have get all the dependences used by the chunk
        // And I can compare with dependencies in package.json
        // Finally, I will get external dependencies used by each entry
 
    })
})

But in webpack5:

compiler.hooks.emit.tapAsync('DepsJsonWebpackPlugin', (compilation, done) => {
    compilation.chunks.forEach((chunk) => {
        console.log(chunk.name);
        for (const module of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
          console.log(module.request);
        }
    });
    done();
});

All the dependencies specified in externals lost.

So, how can I get all module dependencies of each entry in webpack5, including the ones that are external

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!