Full Guide: Webpack loaders and Optimization

steveleung9527
2 min readNov 1, 2022

--

This will be the full guide to help you start your React App from scratch with the followings:

  • Webpack 5 (Bundle your app)
  • Babel (Transpile JSX)
  • TypeScript
  • Eslint (Format Code like a pro)
  • Husky (Lint Before Commit)
  • Jest (Testing Library)
  • Micro Front-end (Webpack 5 Module Federation)

Loaders

  • sass-loader — for sass and scss files
  • css-loader — for css modules
  • asset — including images but exclude svg
  • svg — special handling that allow svg is used as component
npm i --save-dev @svgr/webpack sass-loader css-loader mini-css-extract-plugin file-loader less-loader

**You may not need all of these, just pick the packages that you will use

Optimization

Here we will go deeper in webpack config, and optimize it for production. Here are the plugins that will be used for optimization

you can update your webpack.config.ts as follow

Please give me a clap, and follow me if you find the article is useful.

--

--