javascript-obfuscator / javascript-obfuscator/webpack-obfuscator

How to onfuscate only my own code using webpack-obfuscator?

未关闭
#178 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
928
派生
92
PR 合并指标
30 天内没有已合并 PR

描述

I'm building an electron application using TypeScript and WebPack. I want to process my own code without touching any 3rd party dependencies in order to rename only my own classes property names.

I've tried to use two approaches but with no success:
1) Using plugin

```typescript
import path from 'node:path';
import type { Configuration } from 'webpack';

import { rules } from './webpack.rules';
import WebpackObfuscator from 'webpack-obfuscator';

export const mainConfig: Configuration = {
/**
* This is the main entry point for your application, it's the first file
* that runs in the main process.
*/
entry: "./src/index.ts",
// Put your normal webpack config below here
module: {
rules
},
plugins: [
new WebpackObfuscator({
sourceMap: true,
renameProperties: true,
rotateStringArray: true
}, "node_modules/")
],
resolve: {
extensions: [".js", ".ts", ".jsx", ".tsx", ".css", ".json"],
// Workaround to make import aliases ("paths" from tscondig.json) work
// https://stackoverflow.com/a/75373097/6698055
alias: {
"@domain": path.resolve(__dirname, "src/domain"),
"@platform": path.resolve(__dirname, "src/platform"),
"@build_src": path.resolve(__dirname, "build_src")
}
}
};
```

2) Using loader

```typescript
import type { ModuleOptions } from 'webpack';
import WebpackObfuscator from 'webpack-obfuscator';
import path from 'node:path'

export const rules: Required["rules"] = [
// Add support for native node modules
{
// We're specifying native_modules in the test because the asset relocator loader generates a
// "fake" .node file which is really a cjs file.
test: /native_modules[/\\].+\.node$/,
use: "node-loader"
},
{
test: /[/\\]node_modules[/\\].+\.(m?js|node)$/,
parser: { amd: false },
use: {
loader: "@vercel/webpack-asset-relocator-loader",
options: {
outputAssetBase: "native_modules"
}
}
},
{
test: /\.js$/,
enforce: 'post', // Ensure this loader will be called after normal loaders
use: {
loader: WebpackObfuscator.loader,
options: {
rotateStringArray: true,
renameProperties: true
}
}
}
];
```

How can I force WebPack to process only my own code without touching any dependencies?

贡献指南

这个仓库没有索引到贡献指南

调研方向

从 webpack 主配置和 webpack.rules 中的规则开始,重点检查针对捆绑模块的插件和加载器匹配项。运行 Electron webpack 构建并检查其输出,以确定哪些模块已被混淆。完成的标准是:应用自身的 TypeScript 代码经过处理,而第三方依赖保持不变。

由索引模型根据 Issue 内容生成。

评估

技术栈
electron, typescript, webpack
领域
build-system, desktop
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。