Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to minify/uglify webworker bundles built with Angular in production

I need to use web-workers for heavy computation and Angular provides a convenient way to generate a web-worker in an application with the CLI command ng generate web-worker app.

The issue is, when built in production using ng build --prod, the generated web-worker bundle doesn't appear to be well optimized. I still can find whole variable, class or method names in the file, and some parts of the code is easy to read on the bundle, which struggles me.

Is there a way to better minify that code?

Regards,

EDIT: To give an example, here is the content of app.worker.ts:

/// <reference lib="webworker" />
class MyClassName{
  myMethodName(){}
}
const myVariableName = new MyClassName()
postMessage(myVariableName.myMethodName());

And this can be found inside the worker.js file generated with ng build --prod

const myVariableName=new class{myMethodName(){}};postMessage(myVariableName.myMethodName())}});

the code is optimized but is still easy to read.

EDIT 2: typo

like image 430
Verrick Avatar asked Oct 13 '25 02:10

Verrick


1 Answers

edit your angular.json and set optimization:true

https://angular.io/guide/workspace-config#build-configs

like image 74
Garine Avatar answered Oct 14 '25 15:10

Garine