Skip to content

Commit a5a3fa7

Browse files
committed
refactor(plugin): rename worker-related options to obfuscateWorker and obfuscateWorkerExcludes
- Replace `worker` with `obfuscateWorker` and `workerExcludes` with `obfuscateWorkerExcludes` for clarity. - Update related implementation, tests, and documentation to reflect these changes.
1 parent 2161e9a commit a5a3fa7

6 files changed

Lines changed: 23 additions & 23 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,17 @@ export default {
157157

158158
## 🧵 Web Worker Support
159159

160-
By default, worker bundles generated from `?worker` / `new Worker(new URL(...))` are also obfuscated.
160+
By default, worker bundles generated from `?worker` / `new Worker(new URL(...))` are **not** obfuscated.
161161

162-
Disable worker obfuscation:
162+
Enable worker obfuscation:
163163

164164
```js
165165
import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator';
166166

167167
export default {
168168
plugins: [
169169
vitePluginBundleObfuscator({
170-
worker: false,
170+
obfuscateWorker: true,
171171
}),
172172
],
173173
};
@@ -177,7 +177,7 @@ Exclude extra files only for workers:
177177

178178
```js
179179
vitePluginBundleObfuscator({
180-
workerExcludes: [/comlink\\.worker.*\\.js$/],
180+
obfuscateWorkerExcludes: [/comlink\\.worker.*\\.js$/],
181181
});
182182
```
183183

@@ -195,8 +195,8 @@ With **7000+ modules** and **400+ bundles** on a **4C 8G** machine:
195195
| threadPool | Configuration for the thread pool. | boolean \| ({ enable: true; size: number } \| { enable: false }) | false | v1.2.0 |
196196
| 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 |
197197
| 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) |
198-
| worker | Enable or disable obfuscation for Web Worker bundles. | boolean \| { enable: boolean } | true | v1.10.0 |
199-
| workerExcludes | Additional excludes only for workers (final: `excludes + workerExcludes`). | (RegExp \| string)[] | [] | v1.10.0 |
198+
| obfuscateWorker | Enable or disable obfuscation for Web Worker bundles. | boolean \| { enable: boolean } | false | v1.10.0 |
199+
| obfuscateWorkerExcludes | Additional excludes only for workers (final: `excludes + obfuscateWorkerExcludes`). | (RegExp \| string)[] | [] | v1.10.0 |
200200
| log | Show or hide log output. | boolean | true | v1.0.4 |
201201
| enable | Enable or disable the obfuscator. | boolean | true | v1.0.1 |
202202
| excludes | Bundle names to be excluded. Starting from v1.0.8, RegExp is supported. | (RegExp \| string)[] | [] | v1.0.0 |

README.zh-CN.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,17 @@ export default {
155155

156156
## 🧵 Web Worker 支持
157157

158-
默认支持对 `?worker` / `new Worker(new URL(...))` 生成的 worker bundle 进行混淆,无需额外配置
158+
默认**不会** `?worker` / `new Worker(new URL(...))` 生成的 worker bundle 进行混淆。
159159

160-
禁用 worker 混淆:
160+
启用 worker 混淆:
161161

162162
```js
163163
import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator';
164164

165165
export default {
166166
plugins: [
167167
vitePluginBundleObfuscator({
168-
worker: false,
168+
obfuscateWorker: true,
169169
}),
170170
],
171171
};
@@ -175,7 +175,7 @@ export default {
175175

176176
```js
177177
vitePluginBundleObfuscator({
178-
workerExcludes: [/comlink\\.worker.*\\.js$/],
178+
obfuscateWorkerExcludes: [/comlink\\.worker.*\\.js$/],
179179
});
180180
```
181181

@@ -193,8 +193,8 @@ vitePluginBundleObfuscator({
193193
| threadPool | 线程池的配置。 | boolean \| ({ enable: true; size: number } \| { enable: false }) | false | v1.2.0 |
194194
| apply | 仅将插件应用于服务或构建,或在特定条件下。 | 'serve' \| 'build' \| ((this: void, config: UserConfig, env: ConfigEnv) => boolean) | build | v1.1.0 |
195195
| autoExcludeNodeModules | 启用自动排除node_modules。 | boolean \| ({ enable: true; manualChunks: string[] } \| { enable: false }) | false | v1.0.9(原本为boolean,在v1.3.0版本中扩展到当前类型) |
196-
| worker | 启用或禁用 Web Worker 产物混淆。 | boolean \| { enable: boolean } | true | v1.10.0 |
197-
| workerExcludes | 仅对 worker 额外排除(最终:`excludes + workerExcludes`)。 | (RegExp \| string)[] | [] | v1.10.0 |
196+
| obfuscateWorker | 启用或禁用 Web Worker 产物混淆。 | boolean \| { enable: boolean } | false | v1.10.0 |
197+
| obfuscateWorkerExcludes | 仅对 worker 额外排除(最终:`excludes + obfuscateWorkerExcludes`)。 | (RegExp \| string)[] | [] | v1.10.0 |
198198
| log | 显示或隐藏日志输出。 | boolean | true | v1.0.4 |
199199
| enable | 启用或禁用混淆器。 | boolean | true | v1.0.1 |
200200
| excludes | 排除的bundle名。从v1.0.8开始,支持正则。 | (RegExp \| string)[] | [] | v1.0.0 |

src/__tests__/plugin.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ const defaultConfig: Config = {
6767
log: false,
6868
autoExcludeNodeModules: true,
6969
threadPool: true,
70-
worker: true,
71-
workerExcludes: [],
70+
obfuscateWorker: true,
71+
obfuscateWorkerExcludes: [],
7272
options: {}
7373
}
7474

@@ -1047,7 +1047,7 @@ describe('viteBundleObfuscator plugin', () => {
10471047
});
10481048

10491049
it('should not auto inject worker plugin when disabled', () => {
1050-
const plugin = viteBundleObfuscator({worker: false}) as Plugin;
1050+
const plugin = viteBundleObfuscator({obfuscateWorker: false}) as Plugin;
10511051
const config = {} as any;
10521052
const env = {command: 'build', mode: 'production', isSsrBuild: false};
10531053

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default function viteBundleObfuscator(config?: Partial<Config>): PluginOp
6464
_isLibMode = isLibMode(config);
6565
_isNuxtProject = isNuxtProject(config);
6666

67-
if (finalConfig.enable && isEnabledFeature(finalConfig.worker)) {
67+
if (finalConfig.enable && isEnabledFeature(finalConfig.obfuscateWorker)) {
6868
const original = config.worker?.plugins;
6969

7070
config.worker = config.worker || {};
@@ -86,7 +86,7 @@ export default function viteBundleObfuscator(config?: Partial<Config>): PluginOp
8686
if (!finalConfig.enable || !bundle || _isSsrBuild) return;
8787
const workerConfig: Config = {
8888
...finalConfig,
89-
excludes: [...finalConfig.excludes, ...finalConfig.workerExcludes],
89+
excludes: [...finalConfig.excludes, ...finalConfig.obfuscateWorkerExcludes],
9090
};
9191
await obfuscateAllChunks(bundle, { config: workerConfig, log: new Log(workerConfig.log) });
9292
},

src/type.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ export interface Config {
7373
*/
7474
options: ObfuscatorOptions;
7575
/**
76-
* Enable or disable obfuscation for Vite Web Worker bundles.
76+
* Enable or disable obfuscation for Vite Web Worker bundles (?worker imports).
7777
*/
78-
worker: boolean | { enable: boolean };
78+
obfuscateWorker: boolean | { enable: boolean };
7979
/**
80-
* Additional excludes only for worker build (final excludes: excludes + workerExcludes).
80+
* Additional excludes only for worker build (final excludes: excludes + obfuscateWorkerExcludes).
8181
*/
82-
workerExcludes: (RegExp | string)[];
82+
obfuscateWorkerExcludes: (RegExp | string)[];
8383
}

src/utils/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export const defaultConfig: Readonly<Config> = {
77
apply: 'build',
88
autoExcludeNodeModules: false,
99
threadPool: false,
10-
worker: true,
11-
workerExcludes: [],
10+
obfuscateWorker: false,
11+
obfuscateWorkerExcludes: [],
1212
options: {
1313
compact: true,
1414
controlFlowFlattening: true,

0 commit comments

Comments
 (0)