This repo demonstrates from scratch how to customize your angular build with webpack such that the Async CSS Plugin can then be added. The steps taken are listed below, please see the git history for details.
CAUTION: The steps below just reproduce what was reported here. It is currently unclear why this happens or how to fix this. PRs are very welcome!
-
On github.com, create a new repo named
async-css-angular-example
. -
Clone the repo locally.
-
Add this README.md file plus supporting files.
-
Start a terminal and
cd
to the directory above the local copy of this repo. -
Execute the following steps (see https://cli.angular.io):
sudo npm install -g @angular/cli
(version 9.1.6 at the time of this writing).ng new async-css-angular-example
, accepting all defaults.
-
cd async-css-angular-example
-
npm start
-
Start your browser and navigate to http://localhost:4200/ to ensure everything works as expected.
-
Start your editor and open ./angular.json. Under
architect.build.options
add"extractCss": true
and save. Styles are now loaded from css files rather than embedded. -
Switch back to the terminal, stop the server with CTRL-C and execute
npm install @angular-builders/custom-webpack --save-dev
. -
Back in the editor, under
architect.build
set"builder": "@angular-builders/custom-webpack:browser"
. -
Under
architect.build.options
add"customWebpackConfig": { "path": "./custom-webpack.config.js" }
. -
Under
architect.serve
set"builder": "@angular-builders/custom-webpack:dev-server"
and save. -
Create a new file ./custom-webpack.config.js with the following contents:
module.exports = { plugins: [ ] };
-
Back in the terminal, execute
npm start
, switch to your browser and reload. Everything should still work as before. -
In the terminal hit CTRL-C and execute
npm install html-webpack-plugin async-css-plugin --save-dev
. -
In the editor, modify ./custom-webpack.config.js as follows:
const HtmlWebpackPlugin = require('html-webpack-plugin') const AsyncCssPlugin = require("async-css-plugin"); module.exports = { plugins: [ new HtmlWebpackPlugin(), new AsyncCssPlugin({ logLevel: "info" }) ] };
-
Execute
npm run build
. At first we see promising messages in the console:95% emitting HtmlWebpackPlugin AsyncCssPlugin[info]: index.html: Modified link to styles.css.
... but then the generated output under ./dist looks the same as without the plugins.