javascript-obfuscator / javascript-obfuscator/webpack-obfuscator

Exclude files

Open
#166 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
928
Forks
92
PR merge metrics
No merged PRs in 30d

Description

Hello all,

I have used webpack obfuscator previous version for webpack 4 with laravel mix. Now I have been trying this version and it works great, but when it tried to build the service worker always gives me an error saying that it cant find the self.__manifest. I realized that probably some files are being obfuscated and they should not. So, I decided to exclude the files that I was excluding before, but after trying some things, reading the docs and look to the webpackObfuscatorPlugin class and apply what it looks like its the correct way I am not being able to exclude the files I want.

This is the block of code that I am using:
```
if (mix.inProduction()) {
/**
* PWA code
*/
mix.injectManifest({
swSrc: './resources/js/service-worker.js',
swDest: path.join(`${__dirname}/public`, 'service-worker.js'),
mode: 'production',
});

mix.webpackConfig({
plugins: [
new WebpackObfuscator({
//rotateStringArray: true,
compact: true,
controlFlowFlattening: false,
deadCodeInjection: false,
debugProtection: false,
debugProtectionInterval: 0,
disableConsoleOutput: false,
identifierNamesGenerator: 'hexadecimal',
log: false,
numbersToExpressions: false,
renameGlobals: false,
selfDefending: false,
simplify: true,
splitStrings: false,
stringArray: true,
stringArrayCallsTransform: false,
stringArrayCallsTransformThreshold: 0.5,
stringArrayEncoding: [],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 1,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 2,
stringArrayWrappersType: 'variable',
stringArrayThreshold: 0.75,
unicodeEscapeSequence: false,
},
[
path.join(__dirname, 'node_modules'),
path.join(__dirname, 'resources/js/app.js'),
path.join(__dirname, 'resources/js/bootstrap.js'),
path.join(__dirname, 'resources/js/service-worker.js'),
]),
],
});
}
```

Before this I do all the mix.js() to the files that I need for dev and production.

I am missing something important for sure, but can't find what I am doing wrong to exclude those files.

Maybe some mix function as it could be done in the old version?

```
mix.serve('php artisan lang:js')
.obfuscator({
options: {
compact: true,
controlFlowFlattening: false,
deadCodeInjection: false,
debugProtection: false,
debugProtectionInterval: 0,
disableConsoleOutput: false,
identifierNamesGenerator: 'hexadecimal',
log: false,
numbersToExpressions: false,
renameGlobals: false,
selfDefending: false,
simplify: true,
splitStrings: false,
stringArray: true,
stringArrayCallsTransform: false,
stringArrayCallsTransformThreshold: 0.5,
stringArrayEncoding: [],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 1,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 2,
stringArrayWrappersType: 'variable',
stringArrayThreshold: 0.75,
unicodeEscapeSequence: false
},
exclude: [
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, 'resources/js/app.js'),
path.resolve(__dirname, 'resources/js/bootstrap.js'),
path.resolve(__dirname, 'resources/js/service-worker.js'),
]
});
}
```

Thank you for the help :)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the WebpackObfuscator configuration and the webpackObfuscatorPlugin class referenced in the issue, then trace how the exclude paths are matched. Reproduce the Laravel Mix production build involving resources/js/service-worker.js, app.js, and bootstrap.js. Done means the listed files are excluded and the service-worker build completes without the self.__manifest error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.