# electron-vite-obfuscator

> Electron build tooling based on Vite

Latest version **1.0.0** (published 2024-03-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install electron-vite-obfuscator
pnpm add electron-vite-obfuscator
yarn add electron-vite-obfuscator
bun add electron-vite-obfuscator
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-03-19 |
| First published | 2024-03-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^18.0.0 \|\| >=20.0.0 |
| Dependencies | 6 |
| Unpacked size | 40.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Arthur Gerster |
| Maintainers | therealartti |
| Keywords | electron, vite, plugin, obfuscator |

## Links

- npm: https://www.npmjs.com/package/electron-vite-obfuscator
- Repository: https://github.com/therealartti/electron-vite-obfuscator
- Homepage: https://github.com/therealartti/electron-vite-obfuscator#readme
- Issues: https://github.com/therealartti/electron-vite-obfuscator/issues
- npm.io page: https://npm.io/package/electron-vite-obfuscator

## Dependencies (6)

- [esbuild](https://npm.io/package/esbuild.md) ^0.19.8
- [picocolors](https://npm.io/package/picocolors.md) ^1.0.0
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.23.5
- [magic-string](https://npm.io/package/magic-string.md) ^0.30.5
- [javascript-obfuscator](https://npm.io/package/javascript-obfuscator.md) ^4.1.0
- [@babel/plugin-transform-arrow-functions](https://npm.io/package/@babel/plugin-transform-arrow-functions.md) ^7.23.3

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2024-03-19

## README

# electron-vite-obfuscator
An obfuscation extension to [electron-vite](https://github.com/alex8088/electron-vite)'s V8 Bytecode plugin  using [javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator).

## Install

```sh
npm i electron-vite-obfuscator -D
```

## Usage

Similarly to how the official Bytecode plugin works, use the plugin bytecodePlugin to enable bytecode protection:

```js
import { defineConfig } from 'electron-vite'
import { bytecodePlugin } from 'electron-vite-obfuscator'

export default defineConfig({
  main: {
    plugins: [bytecodePlugin()]
  },
  preload: {
    plugins: [bytecodePlugin()]
  },
  renderer: {
    // ...
  }
})
```

## Configure

To enable the javascript obfuscation, pass the wanted obfuscator settings in the obfuscationOptions object. Refer to the javascript-obfuscator [official documentation](https://github.com/javascript-obfuscator/javascript-obfuscator?tab=readme-ov-file#javascript-obfuscator-options) to see all possible options. 

```js
import { defineConfig } from 'electron-vite'
import { bytecodePlugin } from 'electron-vite-obfuscator'

export default defineConfig({
  main: {
    plugins: [
      bytecodePlugin({ 
        obfuscationOptions: { 
          //options go here 
        }
      })
    ]
  },
  preload: {
// ...
})
```

> [!IMPORTANT]  
> Both `selfDefending` and `debugProtection` depend on `Function.prototype.toString()`. According to the electron-vite [docs](https://electron-vite.org/guide/source-code-protection#impact-on-code-organization-and-writing), the function does not work due to bytecode's nature. Thus, `selfDefending` and `debugProtection` are enforced to `false`.

### Official bytecodePlugin Options

On top of `obfuscationOptions`, all official electron-vite bytecodePlugin options (`protectedStrings`, `transformArrowFunctions`, etc) **are** supported. They can be found [here](https://electron-vite.org/guide/source-code-protection#bytecodeplugin-options).

## FAQ

### Why make a separate npm package instead of a PR?

Based on my own understanding, having extra obfuscation supported is not in the roadmap of electron-vite. By making a separate package, I can improve and work on this without cluttering and making electron-vite deviate from its original purpose. Of course, if [alex.wei](https://github.com/alex8088) does want to include my changes, he's free to do so.

### Why use this package instead of another vite javascript-obfuscator plugin?

First of all, the obfuscation process is embedded in the bytecode transformation process. Therefore you are sure that everything works as it should, and when it should. Second of all, `stringArray` works perfectly compared to other modern alternatives that enforce it to `false`.

### Why doesn't my application work?

The larger the project, the more problems you stumble upon. Before submitting an issue, try playing around with the different javascript-obfuscator settings. 

## Support

- Create an [issue](https://github.com/therealartti/electron-vite-obfuscator/issues)

---
_Source: https://npm.io/package/electron-vite-obfuscator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
