Set up Master CSS in Angular

Guide to setting up Master CSS in your Angular project.

Master CSS Static Extraction integrates build tools to scan project source code, extract class names, generate CSS rules, and write them into a virtual CSS module.

Zero runtime

Generate virtual CSS modules at build time


Scan all source code to extract class names

Cross-page caching

Download the CSS bundle for all pages at once

Quick start

Clone the example

Copy-paste the following commands to quickly start using the

You can skip all installation steps.

npx degit master-co/css/examples/angular-with-static-extraction my-project
cd my-project
npm install @master/css@beta
npm install
npm run dev


Create a project

If you don't have a Angular project, create one first. It's recommended to refer Angular CLI.

ng new project
cd project

Install Master CSS and others

Install the Master CSS and Angular custom webpack plugin into your project via package managers.

npm install @master/css-extractor.webpack@beta @angular-builders/custom-webpack

Initialize configuration file

Run npx mcss init to create a configuration file master.css.ts.

npx mcss init

Set up CSS extractor

  • Create a webpack.config.js file
  • Add a CSSExtractorPlugin to the plugins
const { CSSExtractorPlugin } = require('@master/css-extractor.webpack')
module.exports = (config) => {
new CSSExtractorPlugin({
sources: ['src/index.html']
return config

Configure Angular

Use @angular-builders/custom-webpack instead of the default builder for custom webpack configuration.

"projects": {
"my-project": {
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./webpack.config.js"
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"builder": "@angular-builders/custom-webpack:dev-server",
"options": {
"browserTarget": "my-project:build"

Import virtual CSS module

Import the master.css virtual CSS module into the global CSS file src/styles.css.

Don't import it in the src/main.ts, you'll get some errors about webpack loaders.

/* You can add global styles to this file, and also import other style files */
@import '.virtual/master.css';

Launch server

Run the development server.

npm run start

Start using Master CSS

Now style your first element using Master CSS syntax!

<h1 class="font:40 font:heavy italic m:50 text:center">Hello World</h1>

Open your browser to watch the changes.


Hello World

MIT License © Aoyue Design LLC.