javascript-obfuscator / javascript-obfuscator/webpack-obfuscator
How to onfuscate only my own code using webpack-obfuscator?
- Ngôn ngữ chính
- TypeScript
- Star
- 928
- Fork
- 92
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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?
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Bắt đầu với cấu hình webpack chính và các rule trong webpack.rules, tập trung vào các kết quả khớp của plugin và loader đối với các module được đóng gói. Chạy bản build webpack của Electron và kiểm tra đầu ra của nó để xác định module nào bị làm rối. Hoàn thành có nghĩa là mã TypeScript của chính ứng dụng được xử lý, trong khi các dependency của bên thứ ba vẫn không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- electron, typescript, webpack
- Lĩnh vực
- build-system, desktop
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100