Old Angular tutorials talk about systemjs.config.js and webpack.config.js. You do not need to write either today. This short lesson explains what they were, so old articles make sense.
What you will learn
- What a module loader and a bundler are
- The history: SystemJS, then Webpack, then esbuild and Vite
- What you do (and do not) configure today
The problem they solve
Your code is split into hundreds of files that import each other. Browsers originally could not load that. Something had to find every file, join them and deliver something the browser can run.
- A module loader loads modules while the page runs, in the browser. SystemJS did this in the earliest Angular versions. You wrote a config file telling it where
@angular/corelived, and the browser downloaded many small files. - A bundler does the work at build time. It follows all the
importlines, removes unused code (tree shaking), minifies and writes a few optimised files. Webpack became the standard, and Angular used it from version 6 to 16 behind the CLI. Config files were hidden inside the CLI; some projects used custom builders. - Since Angular 17 the default is esbuild for building and Vite for the dev server (
ng serve). They are much faster. You still runng build.
Today's flow
- You write standalone components and
importthem. ng builduses@angular/build(esbuild) to bundle and optimise.- The result in
dist/<app>/browseris plain files:index.html, JavaScript, CSS. - Any static server can host them.
Lazy loading is a loader feature
Lazy loading still uses a loader idea, now the browser's native dynamic import:
// File: dynamic import
const module = await import('./reports/reports.routes');
The bundler turns each import() into a separate file (a *chunk*) that downloads only when needed. That is exactly what loadComponent and loadChildren do.
What should you configure?
- Normally nothing. Use
angular.jsonfor options (styles, assets, budgets, file replacements). - Add the packages you need with
npm installandng add. - Do not add Webpack or SystemJS to a new Angular project. If an old project still uses the Webpack browser builder, upgrade with
ng updateand the migration to theapplicationbuilder.
Common mistakes
- Following a tutorial for Angular 2 to 4 in a new project.
- Installing Webpack plugins that the esbuild builder cannot use.
- Importing the same large library in many lazy routes without checking the bundle size (use
ng build --stats-jsonand an analyser).
Try it yourself
- Run
ng buildand opendist/<app>/browser. Count the JavaScript chunks. - Add a lazy route and see a new chunk appear.
- Check
angular.jsonand find thebuildervalue of yourbuildtarget.
Quick check
- What is the difference between a module loader and a bundler?
- Which tools build Angular today?
- How does lazy loading create a separate file?
Next, put everything together in the advanced capstone.