Skip to content

Commit d89b946

Browse files
authored
feat: optimize (#25)
* feat: optimize * feat: optimize --------- Co-authored-by:   < >
1 parent b44f60a commit d89b946

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
var C=Object.defineProperty;var u=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var g=(e,o,r)=>o in e?C(e,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[o]=r,l=(e,o)=>{for(var r in o||(o={}))v.call(o,r)&&g(e,r,o[r]);if(u)for(var r of u(o))A.call(o,r)&&g(e,r,o[r]);return e};import*as n from"vite";import E from"javascript-obfuscator";function p(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function d(e){return Object.prototype.toString.call(e)==="[object String]"}var i=class{constructor(o){this.show=o;this._log=o?console.log.bind(console):this.noop}noop(o){}alwaysLog(...o){console.log(...o)}info(o){this._log(o)}};function m(e){let o=Math.floor(e/36e5),r=Math.floor(e%36e5/6e4),t=Math.floor(e%6e4/1e3);return[o?`${o}h `:"",r?`${r}m `:"",t||!o&&!r?`${t}s`:""].filter(Boolean).join("")}var b={excludes:[],enable:!0,log:!0,options:{compact:!0,controlFlowFlattening:!0,controlFlowFlatteningThreshold:1,deadCodeInjection:!1,debugProtection:!1,debugProtectionInterval:0,disableConsoleOutput:!1,identifierNamesGenerator:"hexadecimal",log:!1,numbersToExpressions:!1,renameGlobals:!1,selfDefending:!0,simplify:!0,splitStrings:!1,stringArray:!1,stringArrayCallsTransform:!1,stringArrayCallsTransformThreshold:.5,stringArrayEncoding:[],stringArrayIndexShift:!0,stringArrayRotate:!0,stringArrayShuffle:!0,stringArrayWrappersCount:1,stringArrayWrappersChainedCalls:!0,stringArrayWrappersParametersMaxCount:2,stringArrayWrappersType:"variable",stringArrayThreshold:.75,unicodeEscapeSequence:!1}};function x(e,o){for(let r of o)if(p(r)){if(r.test(e))return!0}else if(d(r)&&e.includes(r))return!0;return!1}function T(){return n!=null&&n.version?Number(n.version.split(".")[0]):2}function j(e){let o=l(l({},b),e),r=new i(o.log),t=(f,{bundle:c})=>{if(!o.enable||!c)return f;let y=performance.now();r.alwaysLog("starting obfuscation process..."),Object.entries(c).forEach(([a,s])=>{"code"in s&&s.code&&!x(a,o.excludes)&&(r.info(`obfuscating ${a}...`),s.code=E.obfuscate(s.code,o.options).getObfuscatedCode(),r.info(`obfuscation complete for ${a}.`))});let h=m(performance.now()-y);return r.alwaysLog("\x1B[36m%s\x1B[0m %s","\u2713",`obfuscation process completed in ${h}.`),f};return{name:"vite-plugin-bundle-obfuscator",transformIndexHtml:T()>=5?{order:"post",handler:t}:{enforce:"post",transform:t}}}export{j as default};
1+
var y=Object.defineProperty;var u=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var g=(e,o,r)=>o in e?y(e,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[o]=r,l=(e,o)=>{for(var r in o||(o={}))h.call(o,r)&&g(e,r,o[r]);if(u)for(var r of u(o))C.call(o,r)&&g(e,r,o[r]);return e};import*as n from"vite";import T from"javascript-obfuscator";var i=class{constructor(o){this.show=o;this._log=o?console.log.bind(console):this.noop}noop(o){}alwaysLog(...o){console.log(...o)}info(o){this._log(o)}};function p(e){let o=Math.floor(e/36e5),r=Math.floor(e%36e5/6e4),t=Math.floor(e%6e4/1e3);return[o?`${o}h `:"",r?`${r}m `:"",t||!o&&!r?`${t}s`:""].filter(Boolean).join("")}var d={excludes:[],enable:!0,log:!0,options:{compact:!0,controlFlowFlattening:!0,controlFlowFlatteningThreshold:1,deadCodeInjection:!1,debugProtection:!1,debugProtectionInterval:0,disableConsoleOutput:!1,identifierNamesGenerator:"hexadecimal",log:!1,numbersToExpressions:!1,renameGlobals:!1,selfDefending:!0,simplify:!0,splitStrings:!1,stringArray:!1,stringArrayCallsTransform:!1,stringArrayCallsTransformThreshold:.5,stringArrayEncoding:[],stringArrayIndexShift:!0,stringArrayRotate:!0,stringArrayShuffle:!0,stringArrayWrappersCount:1,stringArrayWrappersChainedCalls:!0,stringArrayWrappersParametersMaxCount:2,stringArrayWrappersType:"variable",stringArrayThreshold:.75,unicodeEscapeSequence:!1}};function v(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function A(e){return Object.prototype.toString.call(e)==="[object String]"}function m(e,o){for(let r of o)if(v(r)){if(r.test(e))return!0}else if(A(r)&&e.includes(r))return!0;return!1}function E(){return n!=null&&n.version?Number(n.version.split(".")[0]):2}function j(e){let o=l(l({},d),e),r=new i(o.log),t=(f,{bundle:c})=>{if(!o.enable||!c)return f;let b=performance.now();r.alwaysLog("starting obfuscation process..."),Object.entries(c).forEach(([a,s])=>{"code"in s&&s.code&&!m(a,o.excludes)&&(r.info(`obfuscating ${a}...`),s.code=T.obfuscate(s.code,o.options).getObfuscatedCode(),r.info(`obfuscation complete for ${a}.`))});let x=p(performance.now()-b);return r.alwaysLog("\x1B[36m%s\x1B[0m %s","\u2713",`obfuscation process completed in ${x}.`),f};return{name:"vite-plugin-bundle-obfuscator",transformIndexHtml:E()>=5?{order:"post",handler:t}:{enforce:"post",transform:t}}}export{j as default};

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type {IndexHtmlTransformHook, PluginOption} from 'vite';
22
import * as vite from 'vite';
33
import type {Config} from "./type";
44
import javascriptObfuscator from 'javascript-obfuscator';
5-
import {isFileNameExcluded, defaultConfig, formatTime, Log} from "./utils";
5+
import {defaultConfig, formatTime, Log} from "./utils";
6+
import {isFileNameExcluded} from "./utils/is";
67

78
function getViteMajorVersion() {
89
return vite?.version ? Number(vite.version.split('.')[0]) : 2

src/utils/index.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {Config} from "../type";
2-
import {isRegExp, isString} from './is';
32

43
export class Log {
54
private readonly _log: (msg: string) => void;
@@ -66,14 +65,3 @@ export const defaultConfig: Readonly<Config> = {
6665
unicodeEscapeSequence: false,
6766
}
6867
};
69-
70-
export function isFileNameExcluded(name: string, excludes: (RegExp | string)[]): boolean {
71-
for (const exclude of excludes) {
72-
if (isRegExp(exclude)) {
73-
if (exclude.test(name)) return true;
74-
} else if (isString(exclude)) {
75-
if (name.includes(exclude)) return true;
76-
}
77-
}
78-
return false;
79-
}

src/utils/is.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@ export function isRegExp(input: any): input is RegExp {
55
export function isString(input: any): input is string {
66
return Object.prototype.toString.call(input) === '[object String]';
77
}
8+
9+
export function isFileNameExcluded(name: string, excludes: (RegExp | string)[]): boolean {
10+
for (const exclude of excludes) {
11+
if (isRegExp(exclude)) {
12+
if (exclude.test(name)) return true;
13+
} else if (isString(exclude)) {
14+
if (name.includes(exclude)) return true;
15+
}
16+
}
17+
return false;
18+
}

0 commit comments

Comments
 (0)