Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/z0ffy/vite-plugin-bundle-obfuscator
Javascript obfuscator plugin for Vite environments
https://github.com/z0ffy/vite-plugin-bundle-obfuscator
Last synced: 25 days ago
JSON representation
Javascript obfuscator plugin for Vite environments
- Host: GitHub
- URL: https://github.com/z0ffy/vite-plugin-bundle-obfuscator
- Owner: z0ffy
- License: mit
- Created: 2024-07-23T03:55:58.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-23T06:22:05.000Z (5 months ago)
- Last Synced: 2024-08-24T03:23:43.356Z (5 months ago)
- Language: TypeScript
- Homepage:
- Size: 56.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- trackawesomelist - vite-plugin-bundle-obfuscator (⭐3) - JavaScript obfuscator. (Recently Updated / [Aug 26, 2024](/content/2024/08/26/README.md))
- fucking-awesome-vite - vite-plugin-bundle-obfuscator - JavaScript obfuscator. (Plugins / Framework-agnostic Plugins)
- awesome-vite - vite-plugin-bundle-obfuscator - JavaScript obfuscator. (Plugins / Framework-agnostic Plugins)
README
# vite-plugin-bundle-obfuscator
JavaScript `obfuscator` plugin for `Vite` environments
[![awesome-vite](https://awesome.re/badge.svg)](https://github.com/vitejs/awesome-vite)
[![][npm-release-shield]][npm-release-link]
[![][npm-downloads-shield]][npm-release-link]
[![][github-releasedate-shield]][github-releasedate-link]
[![][github-license-shield]][github-license-link][Changelog](./CHANGELOG.md) · [Report Bug][github-issues-link] · [Request Feature][github-pr-link]
English | 中文![](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)
[npm-release-shield]: https://img.shields.io/npm/v/vite-plugin-bundle-obfuscator?color=369eff&labelColor=black&logo=npm&logoColor=white
[npm-downloads-shield]: https://img.shields.io/npm/dt/vite-plugin-bundle-obfuscator?color=red&labelColor=black&logo=npm&logoColor=white
[npm-release-link]: https://www.npmjs.com/package/vite-plugin-bundle-obfuscator
[github-releasedate-shield]: https://img.shields.io/github/release-date/z0ffy/vite-plugin-bundle-obfuscator?labelColor=black
[github-releasedate-link]: https://github.com/z0ffy/vite-plugin-bundle-obfuscator/releases
[github-issues-shield]: https://img.shields.io/github/issues/z0ffy/vite-plugin-bundle-obfuscator?color=ff80eb&labelColor=black
[github-issues-link]: https://github.com/z0ffy/vite-plugin-bundle-obfuscator/issues
[github-license-shield]: https://img.shields.io/github/license/z0ffy/vite-plugin-bundle-obfuscator?color=white&labelColor=black
[github-license-link]: https://github.com/z0ffy/vite-plugin-bundle-obfuscator/blob/main/LICENSE
[github-pr-link]: https://github.com/z0ffy/vite-plugin-bundle-obfuscator/pulls
## ⭐️ Features
- ✅ ⚡ Supports `JavaScript obfuscation` in `Vite` projects.
- ✅ 🚀 Multi-threading support for better performfance.
- ✅ ⚙️ Customizable obfuscator options to fit your needs.
- ✅ 🛡️ Auto-excludes `node_modules`.
- ✅ 📦 Support the `node_modules` split chunk.## ⚠️ Notice
- If the obfuscation option `stringArray` is `true`.
- Your results may lose some bundles (in `__vite__mapDeps` array).
- I'm looking for an accurate case.
- If a memory overflow occurs, modify the packaging command to
`"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vite build"`, where `max-old-space-size` is set according
to the configuration.
- When setting up `node_modules` split 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.## 🌐 Online
✦ [Vite - Vanilla](https://stackblitz.com/edit/vitejs-vite-zsytij?file=vite.config.js)
✦ [Vite - Vue](https://stackblitz.com/edit/vitejs-vite-ywho91?file=vite.config.js)
✦ [Vite - React](https://stackblitz.com/edit/vitejs-vite-wyeur4?file=vite.config.js)
✦ [Vite - PReact](https://stackblitz.com/edit/vitejs-vite-oujmks?file=vite.config.js)
✦ [Vite - lit](https://stackblitz.com/edit/vitejs-vite-ru4gws?file=vite.config.js)
✦ [Vite - Svelte](https://stackblitz.com/edit/vitejs-vite-fthdtu?file=vite.config.js)
✦ [Vite - Solid](https://stackblitz.com/edit/vitejs-vite-dcx3eh?file=vite.config.js)
✦ [Vite - Qwik](https://stackblitz.com/edit/vitejs-vite-i2bjvq?file=vite.config.js)
✦ ...## 📦 Installation
```bash
# 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
1. Install the plugin using your preferred package manager.
2. Register the plugin in `vite.config.js`
3. Customize the obfuscator configuration or use the default options.Example:
```javascript
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 }
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,
stringArray: false,
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,
}
};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()
]
};
```## 🚀 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) |
| 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](https://opensource.org/licenses/MIT) License Copyright (c) 2024-present, Zoffy