Skip to content

Instantly share code, notes, and snippets.

@KangHidro
Created April 12, 2024 03:20
Show Gist options
  • Save KangHidro/689debd0087b745e1d047cd8cf7aab82 to your computer and use it in GitHub Desktop.
Save KangHidro/689debd0087b745e1d047cd8cf7aab82 to your computer and use it in GitHub Desktop.

Angular obfuscator guide

Tested Angular 15

Install Deps

npm i -D @angular-builders/custom-webpack@<same-with-angular-ver> webpack-obfuscator

Tested: @angular-builders/custom-webpack@15 and webpack-obfuscator@3.5.1

Config angular.json

"architect": {
  "build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
      "customWebpackConfig": {
        "path": "./extra-webpack.config.js",
        "replaceDuplicatePlugins": true,
        "mergeStrategies": {
          "module.rules": "prepend"
          }
        },
      ...

Config extra-webpack.config.js

Create extra-webpack.config.js same level with angular.json

'use strict';
const WebpackObfuscator = require('webpack-obfuscator');
module.exports = {
  plugins: [
    new WebpackObfuscator({
      compact: true,
      controlFlowFlattening: false,
      deadCodeInjection: false,
      debugProtection: false,
      identifierNamesGenerator: 'hexadecimal',
      numbersToExpressions: false,
      renameGlobals: false,
      selfDefending: false,
      simplify: false,
      splitStrings: false,
      stringArray: true,
      transformObjectKeys: false,
      stringArrayCallsTransform: false,
      stringArrayEncoding: [],
      stringArrayIndexShift: false,
      stringArrayRotate: false,
      stringArrayShuffle: false,
      stringArrayWrappersCount: 0,
      stringArrayWrappersChainedCalls: false,
      stringArrayWrappersParametersMaxCount: 2,
      stringArrayWrappersType: 'variable',
      stringArrayThreshold: 1,
      unicodeEscapeSequence: false,
      renamePropertiesMode: 'safe',
      renameProperties: false
    }, [ '*', '!main.js' ])
  ]
};

Build angular project

Normal build: node node_modules/@angular/cli/bin/ng build --configuration production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment