z0ffy/vite-plugin-bundle-obfuscator
حول
JavaScript obfuscation for Vite 4–8, with library builds, Web Worker support, source maps, and multithreaded processing.
أدوات التطويرما يمكنك فعله
- ✅ ⚡ Supports JavaScript obfuscation in Vite projects.
- ✅ 🚀 Multi-threading support for better performance.
- ✅ ⚙️ Customizable obfuscator options to fit your needs.
- ✅ 🔐 Optional JavaScript Obfuscator Pro API support.
النمو المقاس للنجوم
- خلال 24 ساعة
- ٠
- خلال 7 أيام
- +٢
- خلال 15 يومًا
- +٣
- خلال شهر
- جارٍ جمع السجل
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصل
vite-plugin-bundle-obfuscator
JavaScript obfuscator plugin for Vite environments
📝 Changelog · 🐛 Report Bug · ✨ Request Feature
English | 中文

⭐️ Features
- ✅ ⚡ Supports
JavaScript obfuscationinViteprojects. - ✅ 🚀 Multi-threading support for better performance.
- ✅ ⚙️ Customizable obfuscator options to fit your needs.
- ✅ 🔐 Optional JavaScript Obfuscator Pro API support.
- ✅ 🛡️ Auto-excludes
node_modules. - ✅ 📦 Support the
node_modulessplit chunk.
⚠️ Notice
- If a memory overflow occurs, modify the packaging command to
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vite build", wheremax-old-space-sizeis set according to the configuration. - When setting up
node_modulessplit chunk, please place the accurate package name at the front. For example: ["vue-router", "vue"], "vue" can match both "vue" and "vue-router" at the same time. - Library builds are obfuscated late in
generateBundle. The defaultselfDefending: truerequires that the generated code is not reformatted or processed again. For libraries that consumers will rebundle, minify or format, setoptions: { selfDefending: false }when building the library and verify the consumer's production output.build.minify: truealone does not guarantee compatibility. - For library builds, run this plugin after any other
generateBundlehooks withorder: 'post'that modify chunk code. Hooks with the same order follow the resolved plugin order, including Vite'senforceordering. LatergenerateBundleorwriteBundlecode changes are incompatible withselfDefending: true; adjust the plugin order or disableselfDefendingfor that pipeline. - An explicitly configured
threadPool.sizemust be a positive integer. UsethreadPool: truefor the default CPU-based pool size; invalid sizes fail the build instead of skipping obfuscation. - Library filenames containing
[hash]account for the obfuscation options. With a random seed (the default) or the Pro API, these hashes change on every build. Fixed filenames still need a versioning or cache invalidation strategy. Publish JavaScript and its sourcemaps together. - Some helpers generated by
javascript-obfuscator, including control-flow transformations, may have no original source position. Their stack frames can remain unmapped even with composed sourcemaps.
🌐 Online
✦ Vite - Vanilla ✦ Vite - Vue ✦ Vite - React ✦ Vite - PReact ✦ Vite - lit ✦ Vite - Svelte ✦ Vite - Solid ✦ Vite - Qwik ✦ ...
📦 Installation
# Using npm
npm install vite-plugin-bundle-obfuscator -D
# Using pnpm
pnpm add vite-plugin-bundle-obfuscator -D
# Using yarn
yarn add vite-plugin-bundle-obfuscator -D
👨💻 Usage
- Install the plugin using your preferred package manager.
- Register the plugin in
vite.config.js - Customize the obfuscator configuration or use the default options.
Example:
import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator';
// All configurations
const allObfuscatorConfig = {
excludes: [],
enable: true,
log: true,
autoExcludeNodeModules: true,
// autoExcludeNodeModules: { enable: true, manualChunks: ['vue'] }
threadPool: true,
// threadPool: { enable: true, size: 4 }
pro: false,
options: {
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1,
deadCodeInjection: false,
debugProtection: false,
debugProtectionInterval: 0,
disableConsoleOutput: false,
identifierNamesGenerator: 'hexadecimal',
log: false,
numbersToExpressions: false,
renameGlobals: false,
selfDefending: true,
simplify: true,
splitStrings: false,
ignoreImports: true,
stringArray: true,
stringArrayCallsTransform: true,
stringArrayCallsTransformThreshold: 0.5,
stringArrayEncoding: [],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 1,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 2,
stringArrayWrappersType: 'variable',
stringArrayThreshold: 0.75,
unicodeEscapeSequence: false,
}
};
export default {
plugins: [
vitePluginBundleObfuscator(allObfuscatorConfig)
]
};
// Simplified configurations
const minimizeObfuscatorConfig = {
autoExcludeNodeModules: true,
// autoExcludeNodeModules: { enable: true, manualChunks: ['vue'] }
threadPool: true,
// threadPool: { enable: true, size: 4 }
};
export default {
plugins: [
vitePluginBundleObfuscator(minimizeObfuscatorConfig)
]
};
// Default configurations
export default {
plugins: [
vitePluginBundleObfuscator()
]
};
🔐 JavaScript Obfuscator Pro API
Pro API support is disabled by default. Enable it only when you need javascript-obfuscator Pro features such as vmObfuscation or parseHtml.
import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator';
export default {
plugins: [
vitePluginBundleObfuscator({
pro: {
enable: true,
apiToken: process.env.JAVASCRIPT_OBFUSCATOR_PRO_API_TOKEN,
version: '5.0.3',
timeout: 300000,
},
options: {
vmObfuscation: true,
vmBytecodeFormat: 'binary',
compact: true,
},
}),
],
};
pro only configures the Pro API call. All obfuscation options, including Pro options such as vmObfuscation, vmBytecodeFormat, optionsPreset, and parseHtml, should stay in options.
🧵 Web Worker Support
By default, worker bundles generated from ?worker / new Worker(new URL(...)) are not obfuscated.
Enable worker obfuscation:
import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator';
export default {
plugins: [
vitePluginBundleObfuscator({
obfuscateWorker: true,
}),
],
};
Exclude extra files only for workers:
vitePluginBundleObfuscator({
obfuscateWorkerExcludes: [/comlink\\.worker.*\\.js$/],
});
🚀 Performance Comparison
With 7000+ modules and 400+ bundles on a 4C 8G machine:
- ThreadPool Enabled : 🟩🟩🟩⬜⬜⬜⬜⬜⬜ (About 30 seconds)
- ThreadPool Disabled : 🟥🟥🟥🟥🟥🟥🟥🟥🟥 (About 90 seconds)
🛠️ Options
| Property Name | Description | Type | Default | Version |
|---|---|---|---|---|
| threadPool | Configuration for the thread pool. | boolean | ({ enable: true; size: number } | { enable: false }) | false | v1.2.0 |
| apply | Apply the plugin only for serve or build, or on certain conditions. | 'serve' | 'build' | ((this: void, config: UserConfig, env: ConfigEnv) => boolean) | build | v1.1.0 |
| autoExcludeNodeModules | Enable auto exclude node_modules. | boolean | ({ enable: true; manualChunks: string[] } | { enable: false }) | false | v1.0.9 (originally boolean, extended to current type in v1.3.0) |
| obfuscateWorker | Enable or disable obfuscation for Web Worker bundles. | boolean | { enable: boolean } | false | v1.10.0 |
| obfuscateWorkerExcludes | Additional excludes only for workers (final: excludes + obfuscateWorkerExcludes). |
(RegExp | string)[] | [] | v1.10.0 |
| pro | JavaScript Obfuscator Pro API configuration. | false | { enable: boolean; apiToken?: string; version?: string; timeout?: number; onProgress?: (message: string, fileName: string) => void } | false | - |
| log | Show or hide log output. | boolean | true | v1.0.4 |
| enable | Enable or disable the obfuscator. | boolean | true | v1.0.1 |
| excludes | Bundle names to be excluded. Starting from v1.0.8, RegExp is supported. | (RegExp | string)[] | [] | v1.0.0 |
| options | Options for the JavaScript obfuscator. | ObfuscatorOptions | defaultObfuscatorConfig | v1.0.0 |
📄 License
MIT License Copyright (c) 2024-present, Zoffy
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…