Webpack is a module bundler. Webpack takes modules with dependencies and generates static assets representing those modules.
The main interest of using Webpack is that it will compile all your styles - which we advise you to write using Sass - into a single CSS file. This way, your theme will make only one HTTP request for this single file, and since your browser will cache it for later re-use, it will even download this file only once.
The same goes with your JavaScript code. Instead of loading jQuery along with its community plugins, your own custom plugins and any extra code you might need, Webpack compiles and minifies all this JavaScript code into a single file, which will be loaded once - and cached.
If you want to compile your assets using Webpack (and we advise you to), follow these steps:
_dev
folder.npm install
.npm run build
.npm run watch
.The Webpack configuration file for Classic Theme is thus:
assets/css/theme.css
file.assets/js/theme.js
file.It provides proper configuration for compile your Sass or CSS files into a single CSS file.
JavaScript code is written in ES6, and compiled to ES5 with esbuild.