【Plugin】Vite Javascript obfuscator
2024年10月25日 / 4月17日
适用于Vite环境的JavaScript混淆插件
⭐️ 特性
- ⚡ 支持 Vite 项目中的 JavaScript 混淆。
- 🚀 多线程支持,以获得更好的性能。
- ⚙️ 可定制的混淆器选项,以满足您的需求。
- 🛡️ 自动排除 node_modules。
- 📦 支持 node_modules 拆分块。
⚠️ 注意
- 如果打包过程中出现内存溢出。修改打包命令为:cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_CJS_IGNORE_WARNING=true vite build,其中 max-old-space-size 根据机器配置自行设置。
- 在设置 node_modules 分包时,请把准确的包名前置。例如:["vue-router", "vue"],"vue"可以同时匹配到 vue 以及 vue-router。
🌐 在线示例
✦ Vite - Vanilla ✦ Vite - Vue ✦ Vite - React ✦ Vite - PReact ✦ Vite - lit ✦ Vite - Svelte ✦ Vite - Solid ✦ Vite - Qwik ✦ ...
📦 安装
1# 使用npm 2npm install vite-plugin-bundle-obfuscator -D 3 4# 使用pnpm 5pnpm add vite-plugin-bundle-obfuscator -D 6 7# 使用yarn 8yarn add vite-plugin-bundle-obfuscator -D
👨💻 使用
- 使用您首选的软件包管理器安装插件。
- 在vite.config.js中注册插件。
- 自定义混淆器配置或使用默认选项。
示例:
1import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator'; 2 3const defaultObfuscatorConfig = { 4 excludes: [], 5 enable: true, 6 log: true, 7 autoExcludeNodeModules: false, 8 threadPool: false, 9 options: { 10 compact: true, 11 controlFlowFlattening: true, 12 controlFlowFlatteningThreshold: 1, 13 deadCodeInjection: false, 14 debugProtection: false, 15 debugProtectionInterval: 0, 16 disableConsoleOutput: false, 17 identifierNamesGenerator: 'hexadecimal', 18 log: false, 19 numbersToExpressions: false, 20 renameGlobals: false, 21 selfDefending: true, 22 simplify: true, 23 splitStrings: false, 24 ignoreImports: true, 25 stringArray: true, 26 stringArrayCallsTransform: true, 27 stringArrayCallsTransformThreshold: 0.5, 28 stringArrayEncoding: [], 29 stringArrayIndexShift: true, 30 stringArrayRotate: true, 31 stringArrayShuffle: true, 32 stringArrayWrappersCount: 1, 33 stringArrayWrappersChainedCalls: true, 34 stringArrayWrappersParametersMaxCount: 2, 35 stringArrayWrappersType: 'variable', 36 stringArrayThreshold: 0.75, 37 unicodeEscapeSequence: false, 38 } 39}; 40 41export default { 42 plugins: [ 43 // vitePluginBundleObfuscator() 44 vitePluginBundleObfuscator(defaultObfuscatorConfig) 45 ] 46};
cd ..