1
  • I configured Webpack with React but I'm running into all kinds of bugs, like event handlers work differently, importing css is tricky and more...

  • I know all these problems can be addressed but the whole React + Webpack marriage looks so flimsy

  • Is worth the hassle to use React with Webpack in 2021?

  • If someone uses this combo what are the benefits of it?

I know this question was asked before (2|5 years ago) but so much changed after that...

2
  • 1
    Most people use CRA these days, which abstracts the webpack configuration. For inspiration, you could create an app via CRA, then eject it to see how this config is set up. Commented Mar 2, 2021 at 8:35
  • i use this: createapp.dev Commented Mar 2, 2021 at 9:06

1 Answer 1

1

I usually prefer to have my own Webpack configuration instead of create-react-app since it gives me full control over the bundling configuration. But it really depends on the scale, complexity, and other factors of your project.

If your project is a pretty basic SPA, CRA can work fine. Otherwise, you should either have your own Webpack configuration, or use libraries like gatsby.js (for static sites) or next.js (for server-rendered sites).

Keep in mind that configuring Webpack goes beyond simply getting it to properly parse and compile your code. Your site should also load quickly and have good performance scores (load critical CSS/JS, prefetching, code splitting etc.).

In my experience, getting Webpack to do all that is possible, but difficult, which is why gatsby.js/next.js are recommended alternatives.

Both gatsby.js/next.js use Webpack under the hood, so technically you can do it all yourself when you use Webpack, but they do all the heavy lifting for you. So unless you need to do something very specific that neither of these libraries supports, I think you should use them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.