1

Actually, I'm just curious as to why webpack is used in react applications. Why do I still use Webpack to create a dist folder with a dist.js file if I can create a build using npm run build?

Can somebody help me with my confusion?

Sohaib Butt
  • 57
  • 1
  • 8
  • In your package.json, what does it say under the `bulid` field? – General Grievance Jan 18 '23 at 14:18
  • @GeneralGrievance i didn't implement the webpack. I'm just asking why we use webpack – Sohaib Butt Jan 18 '23 at 14:19
  • 1
    General Grievance is trying to point out that `npm run build` doesn't do a build on its own. It just runs whatever is under scripts/build in your package.json, and that probably IS webpack if you have a look. – Rich N Jan 18 '23 at 14:20
  • @RichN Thank you for clearing the point. Is webpack comes with react app ? – Sohaib Butt Jan 18 '23 at 14:23
  • No, it's a separate thing. A 'module bundler'. There are other module bundlers, like rollup, that people use, but I think webpack is probably the most popular. – Rich N Jan 18 '23 at 14:25
  • Ok @RichN and what's the purpose of webpack – Sohaib Butt Jan 18 '23 at 14:25
  • 1
    You answered that in your question: it takes separate JavaScript files and combines them into one file (dist.js in your case) – Rich N Jan 18 '23 at 14:26
  • Yes yes. You are not getting my point. If create-react-app work flow is okay then why we setup config webpack to unpack the bundle – Sohaib Butt Jan 18 '23 at 14:33

0 Answers0