What configuration should be used to obfuscate Angular 18 project with javascript-obfuscator ?
I am using package.json
{
"name": "angular.dev",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "NG_BUILD_PARALLEL_TS=0 ng serve",
"build": "ng build --configuration production",
"watch": "ng build --watch --configuration development"
},
"private": true,
"dependencies": {
"@angular/animations": "^18.0.0",
"@angular/cdk": "^18.0.0",
"@angular/common": "^18.0.0",
"@angular/compiler": "^18.0.0",
"@angular/core": "^18.0.0",
"@angular/forms": "^18.0.0",
"@angular/material": "^18.0.0",
"@angular/platform-browser": "^18.0.0",
"@aws-amplify/ui-angular": "^5.0.19",
"aws-amplify": "^6.5.3",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.0"
},
"devDependencies": {
"@angular-builders/custom-webpack": "^18.0.0",
"@angular/build": "^18.0.1",
"@angular/cli": "^18.0.0",
"@angular/compiler-cli": "^18.0.0",
"javascript-obfuscator": "^4.1.1",
"typescript": "~5.5.0",
"webpack-cli": "^5.1.4"
}
}
with Angular 18, javascript-obfuscator version 4.1.1 and @angular-builders/custom-webpack version 18.0.0
My angular.json file is
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"first-app": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"inlineTemplate": true,
"inlineStyle": true,
"style": "scss",
"skipTests": true
},
"@schematics/angular:class": {
"skipTests": true
},
"@schematics/angular:directive": {
"skipTests": true
},
"@schematics/angular:guard": {
"skipTests": true
},
"@schematics/angular:interceptor": {
"skipTests": true
},
"@schematics/angular:pipe": {
"skipTests": true
},
"@schematics/angular:resolver": {
"skipTests": true
},
"@schematics/angular:service": {
"skipTests": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./webpack.config.js"
},
"main": "src/main.ts",
"outputPath": "dist/first-app",
"index": "src/index.html",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kB",
"maximumError": "1MB"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kB",
"maximumError": "4kB"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular/build:dev-server",
"configurations": {
"production": {
"buildTarget": "first-app:build:production"
},
"development": {
"buildTarget": "first-app:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular/build:extract-i18n"
}
}
}
},
"cli": {
"analytics": false
}
}
and webpack.config.js is
const JavaScriptObfuscator = require('javascript-obfuscator');
module.exports = {
mode: 'development',
plugins: [
new JavaScriptObfuscator(
{
rotateStringArray: true,
stringArray: true,
stringArrayEncoding: ['rc4'],
stringArrayThreshold: 0.75,
},
['vendor.js']
),
],
};
when I am running this project with npm run build
i am getting the error :
[error] ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration.plugins[12] misses the property 'apply'. Should be:
function
-> The run point of the plugin, required method.
at validate (D:codetempplayground_0-hello-worldnode_moduleswebpacknode_modulesschema-utilsdistvalidate.js:191:11)
at validateSchema (D:codetempplayground_0-hello-worldnode_moduleswebpacklibvalidateSchema.js:78:2)
at create (D:codetempplayground_0-hello-worldnode_moduleswebpacklibwebpack.js:130:24)
at webpack (D:codetempplayground_0-hello-worldnode_moduleswebpacklibwebpack.js:182:32)
at Object.f [as webpackFactory] (D:codetempplayground_0-hello-worldnode_moduleswebpacklibindex.js:73:50)
at createWebpack (D:codetempplayground_0-hello-worldnode_modules@angular-devkitbuild-webpacksrcbuilderswebpackindex.js:28:36)
at runWebpack (D:codetempplayground_0-hello-worldnode_modules@angular-devkitbuild-webpacksrcbuilderswebpackindex.js:40:12)
at D:codetempplayground_0-hello-worldnode_modules@angular-builderscustom-webpacknode_modules@angular-devkitbuild-angularsrcbuildersbrowserindex.js:116:47
at D:codetempplayground_0-hello-worldnode_modulesrxjssrcinternaloperatorsswitchMap.ts:109:21
at OperatorSubscriber._this._next (D:codetempplayground_0-hello-worldnode_modulesrxjssrcinternaloperatorsOperatorSubscriber.ts:70:13)
Can anyone suggest which package.json, angular.json and webpack.config.js configuration should be used to obfuscate Angular 18 project using javascript-obfuscator?
Are there any other options to obfuscate Angular 18 project code?