Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make webpack obfuscator config type safe? #180

Open
RareScrap opened this issue Feb 23, 2025 · 0 comments
Open

How to make webpack obfuscator config type safe? #180

RareScrap opened this issue Feb 23, 2025 · 0 comments

Comments

@RareScrap
Copy link

I want to ensure the values I use in my webpack obfuscator config are type safe. But for some reason the TypeScript compiler gives me no error if, for example, I use incorrect values like high-obfuscation123 for optionsPreset:

webpack.config.ts
export const mainConfig: Configuration = {
  // ...
  plugins: [
    // ...
    new WebpackObfuscatorPlugin({
      optionsPreset: "high-obfuscation123", // No compile time errors. Only runtime ones (during webpack running).
      // ...
    })
  ],
  // ...
}

I also tried to access configuration types directly but it causes an another runtime error although VSCode successfully recognize imports:

webpack.config.ts
// ...
import WebpackObfuscatorPlugin from 'webpack-obfuscator';
import { OptionsPreset } from 'javascript-obfuscator/typings/src/enums/options/presets/OptionsPreset';
import { SourceMapMode } from 'javascript-obfuscator/typings/src/enums/source-map/SourceMapMode';
import { SourceMapSourcesMode } from 'javascript-obfuscator/typings/src/enums/source-map/SourceMapSourcesMode';

export const mainConfig: Configuration = {
  // ...
  plugins: [
    // ...
    new WebpackObfuscatorPlugin({
      // ...
      optionsPreset: OptionsPreset.LowObfuscation,
      sourceMapMode: SourceMapMode.Separate,
      sourceMapSourcesMode: SourceMapSourcesMode.Sources,
      stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumericString],
      target: ObfuscationTarget.Node
    })
  ],
  // ...
}

How can I make my webpack obfuscator config type safe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant