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

204
Views
webpack code splitting on dynamic require and dynamic import

I recently worked on my project to do code splitting on language packs. They were packed into the same major shared chunk when using dynamic require(): (like the following, I only pasted a simplified piece to show the syntax)

switch (lang) {
  case 'it':
    return require('./langs/it_IT.json');
  case 'ja':
    return require('./langs/ja_JP.json');
  case 'ko':
    return require('./langs/ko_KR.json');
  default:
    return require('./langs/en_US.json');
}     

This is unexpected for me. I thought dynamic imported pieces would be split into individual chunks. Not until I rewrote the above piece using import(), these language packs were split from the main chunk.

switch (lang) {
  case 'it':
    return import('./langs/it_IT.json');
  case 'ja':
    return import('./langs/ja_JP.json');
  case 'ko':
    return import('./langs/ko_KR.json');
  default:
    return import('./langs/en_US.json');
}    

I've done some research on the difference between require and import, but I didn't find the answer to why webpack didn't code split on dynamic required modules. Can anyone explain the difference between these two methods?

about 4 years ago · Juan Pablo Isaza
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!