main b9bce9a4a32b cached
8 files
8.4 KB
2.4k tokens
5 symbols
1 requests
Download .txt
Repository: elmeet/vite-plugin-javascript-obfuscator
Branch: main
Commit: b9bce9a4a32b
Files: 8
Total size: 8.4 KB

Directory structure:
gitextract_xy2tdofo/

├── .gitignore
├── .prettierignore
├── LICENSE
├── README.md
├── package.json
├── rollup.config.mjs
├── src/
│   └── index.ts
└── tsconfig.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
node_modules
dist

================================================
FILE: .prettierignore
================================================
README.md

================================================
FILE: LICENSE
================================================
MIT License

Copyright (c) 2022 elmeet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: README.md
================================================
# vite-plugin-javascript-obfuscator

A Vite Plugin for [javascript-obfuscator](https://www.npmjs.com/package/javascript-obfuscator)

## Installation

Install the package:

- npm `npm install --save-dev vite-plugin-javascript-obfuscator`
- yarn `yarn add --dev vite-plugin-javascript-obfuscator`
- pnpm `pnpm i vite-plugin-javascript-obfuscator -D`

## Usage

### Example 1

vite.config.js

```javascript
import obfuscatorPlugin from "vite-plugin-javascript-obfuscator";

export default defineConfig({
  plugins: [
    obfuscatorPlugin({
      options: {
        // your javascript-obfuscator options
        debugProtection: true,
        // ...  [See more options](https://github.com/javascript-obfuscator/javascript-obfuscator)
      },
    }),
  ],
});
```

### Example 2

vite.config.js

```javascript
import obfuscatorPlugin from "vite-plugin-javascript-obfuscator";

export default defineConfig({
  plugins: [
    obfuscatorPlugin({
      include: ["src/path/to/file.js", "path/anyjs/**/*.js", /foo.js$/],
      exclude: [/node_modules/],
      apply: "build",
      debugger: true,
      options: {
        // your javascript-obfuscator options
        debugProtection: true,
        // ...  [See more options](https://github.com/javascript-obfuscator/javascript-obfuscator)
      },
    }),
  ],
});
```

### Params

|    Name    | Type | Default | Description   |
| :------------: | :----: | :-----: | :----------------------------------------------------------------------------------------------------: | 
| **`include`**  |  `Array\|String\|RegExp\|Function` | `[/\.(jsx?\|tsx?\|cjs\|mjs)$/]` | Configure this option to include files |
| **`exclude`**  |  `Array\|String\|RegExp\|Function` | `[/node_modules/, /\.nuxt/]`| Configure this option to exclude files |
| **`options`**  |  `Object` | javascript-obfuscator default options | [See more options](https://github.com/javascript-obfuscator/javascript-obfuscator) |
| **`apply`**   | `'serve' \| 'build'` | both serve and build. | By default plugins are invoked for both serve and build. In cases where a plugin needs to be conditionally applied only during serve or build, use the apply property to only invoke them during `vite build` or `vite serve`  |
| **`debugger`** | `Boolean` | `false` | Used for debugging, Print out the path of matching or excluding files. |


================================================
FILE: package.json
================================================
{
  "name": "vite-plugin-javascript-obfuscator",
  "version": "3.1.0",
  "description": "A Vite Plugin for javascript-obfuscator",
  "main": "dist/index.cjs.js",
  "module": "dist/index.es.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "build": "rollup -c rollup.config.mjs",
    "prebuild": "rm -rf dist/*"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/elmeet/vite-plugin-javascript-obfuscator.git"
  },
  "keywords": [
    "vite",
    "obfuscator",
    "obfuscation",
    "uglify",
    "crush",
    "code protection",
    "javascript obfuscator",
    "js obfuscator"
  ],
  "author": "elmeet@163.com",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/elmeet/vite-plugin-javascript-obfuscator/issues"
  },
  "homepage": "https://github.com/elmeet/vite-plugin-javascript-obfuscator#readme",
  "dependencies": {
    "anymatch": "~3.1.3",
    "javascript-obfuscator": "^4.1.0"
  },
  "devDependencies": {
    "@rollup/plugin-node-resolve": "~15.1.0",
    "@rollup/plugin-typescript": "~11.1.1",
    "@types/node": "~20.3.1",
    "rollup": "~3.25.2",
    "typescript": "~5.1.3"
  },
  "files": [
    "dist"
  ]
}


================================================
FILE: rollup.config.mjs
================================================
import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import pkg from "./package.json" assert { type: "json" };
const external = Object.keys(pkg.dependencies);

export default {
  input: "src/index.ts",
  output: [
    {
      file: pkg.main,
      format: "cjs",
    },
    {
      file: pkg.module,
      format: "es",
    },
  ],
  external: external,
  sourcemap: true,
  plugins: [resolve(), typescript()],
};


================================================
FILE: src/index.ts
================================================
import { obfuscate, ObfuscatorOptions } from "javascript-obfuscator";
import anymatch, { Matcher } from "anymatch";
import { resolve } from "path";

const defaultIncludeMatcher = [/\.(jsx?|tsx?|cjs|mjs)$/];
const defaultExcludeMatcher = [/node_modules/, /\.nuxt/];

type Options = {
  /**
   * (Array|String|RegExp|Function) String to be directly matched, string with glob patterns, regular expression test, function that takes the testString as an argument and returns a truthy value if it should be matched. default: ```[/\.(jsx?|tsx?|cjs|mjs)$/]```
   * [See more](https://github.com/micromatch/anymatch)
   */
  include?: Matcher;
  /**
   *  (Array|String|RegExp|Function) String to be directly matched, string with glob patterns, regular expression test, function that takes the testString as an argument and returns a truthy value if it should be matched. default: ```[/node_modules/, /\.nuxt/]```
   * [See more](https://github.com/micromatch/anymatch)
   */
  exclude?: Matcher;
  /**
   * Your javascript-obfuscator options
   * [See more options](https://github.com/javascript-obfuscator/javascript-obfuscator)
   */
  options?: ObfuscatorOptions;
  /**
   * Used for debugging, Print out the path of matching or excluding files
   */
  debugger?: boolean;
  /**
   * By default plugins are invoked for both serve and build. In cases where a plugin needs to be conditionally applied only during serve or build
   * https://vitejs.dev/guide/api-plugin.html
   */
  apply?: "serve" | "build" | ((this: void, config: any, env: any) => boolean);
};

type UnArray<T> = T extends any[] ? never : T;

type AnymatchPattern = UnArray<Matcher>;

function handleMatcher(matcher: Matcher): Matcher {
  matcher = matcher instanceof Array ? matcher : [matcher];
  return matcher.map((matcher: AnymatchPattern): AnymatchPattern => {
    if (typeof matcher !== "string") {
      return matcher;
    }
    return resolve(".", matcher).replace(/\\/g, "/");
  });
}

export default function obfuscatorPlugin(obOptions?: Options) {
  let { include, exclude, options }: Options = obOptions || {};

  const consoleLog = obOptions?.debugger ? console.log.bind(console) : () => {};

  options = options || {};

  const includeMatcher = include
    ? handleMatcher(include)
    : defaultIncludeMatcher;

  const excludeMatcher = exclude
    ? handleMatcher(exclude)
    : defaultExcludeMatcher;

  return {
    name: "vite-plugin-javascript-obfuscator",
    enforce: "post" as "post",
    apply: obOptions?.apply || (() => true),
    transform(src: string, id: string) {
      if (anymatch(excludeMatcher, id, { dot: true })) {
        consoleLog("[::plugin-javascript-obfuscator]::exclude", id);
        return;
      }

      if (anymatch(includeMatcher, id)) {
        consoleLog("[::plugin-javascript-obfuscator]::include matched", id);

        const obfuscationResult = obfuscate(src, options);

        const result = { code: obfuscationResult.getObfuscatedCode() } as {
          map: string;
          code: string;
        };

        if (options?.sourceMap && options?.sourceMapMode !== "inline") {
          result.map = obfuscationResult.getSourceMap();
        }
        return result;
      }

      consoleLog(`[::plugin-javascript-obfuscator]::not matched`, id);
    },
  };
}


================================================
FILE: tsconfig.json
================================================
{
  "include": ["src/**/*.ts"],
  "compilerOptions": {
    "strict": true,
    "target": "es2016",
    "module": "ES6",
    "declaration": true,
    "declarationDir": "./dist",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node"
  }
}
Download .txt
gitextract_xy2tdofo/

├── .gitignore
├── .prettierignore
├── LICENSE
├── README.md
├── package.json
├── rollup.config.mjs
├── src/
│   └── index.ts
└── tsconfig.json
Download .txt
SYMBOL INDEX (5 symbols across 1 files)

FILE: src/index.ts
  type Options (line 8) | type Options = {
  type UnArray (line 35) | type UnArray<T> = T extends any[] ? never : T;
  type AnymatchPattern (line 37) | type AnymatchPattern = UnArray<Matcher>;
  function handleMatcher (line 39) | function handleMatcher(matcher: Matcher): Matcher {
  function obfuscatorPlugin (line 49) | function obfuscatorPlugin(obOptions?: Options) {
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (9K chars).
[
  {
    "path": ".gitignore",
    "chars": 17,
    "preview": "node_modules\ndist"
  },
  {
    "path": ".prettierignore",
    "chars": 9,
    "preview": "README.md"
  },
  {
    "path": "LICENSE",
    "chars": 1063,
    "preview": "MIT License\n\nCopyright (c) 2022 elmeet\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof "
  },
  {
    "path": "README.md",
    "chars": 2335,
    "preview": "# vite-plugin-javascript-obfuscator\n\nA Vite Plugin for [javascript-obfuscator](https://www.npmjs.com/package/javascript-"
  },
  {
    "path": "package.json",
    "chars": 1162,
    "preview": "{\n  \"name\": \"vite-plugin-javascript-obfuscator\",\n  \"version\": \"3.1.0\",\n  \"description\": \"A Vite Plugin for javascript-ob"
  },
  {
    "path": "rollup.config.mjs",
    "chars": 464,
    "preview": "import resolve from \"@rollup/plugin-node-resolve\";\nimport typescript from \"@rollup/plugin-typescript\";\nimport pkg from \""
  },
  {
    "path": "src/index.ts",
    "chars": 3280,
    "preview": "import { obfuscate, ObfuscatorOptions } from \"javascript-obfuscator\";\nimport anymatch, { Matcher } from \"anymatch\";\nimpo"
  },
  {
    "path": "tsconfig.json",
    "chars": 315,
    "preview": "{\n  \"include\": [\"src/**/*.ts\"],\n  \"compilerOptions\": {\n    \"strict\": true,\n    \"target\": \"es2016\",\n    \"module\": \"ES6\",\n"
  }
]

About this extraction

This page contains the full source code of the elmeet/vite-plugin-javascript-obfuscator GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (8.4 KB), approximately 2.4k tokens, and a symbol index with 5 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!