31
loading...
This website collects cookies to deliver better user experience
ng eject
command to expose the webpack configuration. Unfortunately, since version 8, it's not available anymore. Instead, we can specify "projects.*.architect.build.builder" inside our angular.js
to override the webpack config partially - without getting access to the whole thing.ESBuildMinifyPlugin
from esbuild-loader. The in the webpack article, it looked like better speed improvement than the loader itself. As angular is written in typescript, the loader can improve speed, but I'm afraid it will be an even bigger endeavor than this one.$ npm install --save-dev @angular-builders/custom-webpack esbuild-loader
webpack.config.js
with changes we want to apply:const { ESBuildMinifyPlugin } = require("esbuild-loader");
module.exports = (config, options) => {
// if you console log here, you can see what's inside the config
// remove 2 first minimizers, hopeing they are the TerserPlugin
config.optimization.minimizer.shift();
config.optimization.minimizer.shift();
config.optimization.minimizer.unshift(
new ESBuildMinifyPlugin({
target: "es2015", // Syntax to compile to (see options below for possible values)
})
);
return config;
};
angular.json
:"projects": {
"esbuild-loader-ng-cli": {
...
"architect": {
"build": {
- "builder": "@angular-devkit/build-angular:browser",
+ "builder": "@angular-builders/custom-webpack:browser",
...
- "baseHref": "./"
+ "baseHref": "./",
+ "customWebpackConfig": {
+ "path": "./webpack.config.js"
+ }
},
...
"builder": "@angular-builders/custom-webpack:browser"
is necessary for the change to work - without it, the updated config will not even pass the syntax validation.<your-project-path>/dist/esbuild-loader-ng-cli/
:$ npm run build
> [email protected] build
> ng build
✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.
Initial Chunk Files | Names | Size
main.03b0a30b1c3bb39428d7.js | main | 133.79 kB
polyfills.9a3c7adfe54759783845.js | polyfills | 35.99 kB
runtime.b557d7bc6f5a0a2b7c10.js | runtime | 1.02 kB
styles.31d6cfe0d16ae931b73c.css | styles | 0 bytes
| Initial Total | 170.81 kB
Build at: 2021-07-18T09:10:42.459Z - Hash: 02058db989498bb0ecd9 - Time: 11882ms
$ npm run build
> [email protected] build
> ng build
✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.
Initial Chunk Files | Names | Size
main.276f4eb0574e0396c077.js | main | 437.14 kB
polyfills.4a7829fed9a06cc470d3.js | polyfills | 39.22 kB
runtime.1d3895c9b4e2bbd6978f.js | runtime | 1.08 kB
styles.31d6cfe0d16ae931b73c.css | styles | 0 bytes
| Initial Total | 477.43 kB
Build at: 2021-07-18T09:31:40.831Z - Hash: 0a22501608de71af5712 - Time: 7657ms