iniziale
commit
8d9cf61ca7
|
|
@ -0,0 +1 @@
|
|||
node_modules
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
"use strict";
|
||||
|
||||
var javascriptObfuscator = require("javascript-obfuscator");
|
||||
var fs = require("node:fs");
|
||||
var path = require("node:path");
|
||||
function obfuscatorPlugin(obOptions) {
|
||||
let { excludeChunks, options } = obOptions || {};
|
||||
return {
|
||||
name: "vite-plugin-javascript-obfuscator",
|
||||
enforce: "post",
|
||||
apply:
|
||||
(obOptions === null || obOptions === void 0 ? void 0 : obOptions.apply) ||
|
||||
(() => true),
|
||||
async writeBundle(output_options, bundle) {
|
||||
for (let output_file in bundle) {
|
||||
if (bundle[output_file].type != "chunk") {
|
||||
continue;
|
||||
}
|
||||
let chunk = bundle[output_file];
|
||||
if (output_file.match(/\.(js|mjs|cjs)$/)) {
|
||||
if (excludeChunks.indexOf(chunk.name) == -1) {
|
||||
console.log(
|
||||
`[briq-vite-obfuscator-plugin] Obfuscating chunk ${chunk.name} (${output_file}) ...`
|
||||
);
|
||||
let abs_path = path.join(output_options.dir, output_file);
|
||||
const obfuscationResult = javascriptObfuscator.obfuscate(
|
||||
chunk.code,
|
||||
options
|
||||
);
|
||||
let code = obfuscationResult.getObfuscatedCode();
|
||||
await new Promise((resolve, reject) => {
|
||||
fs.writeFile(abs_path, code, (err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log(
|
||||
`[briq-vite-obfuscator-plugin] Ignoring chunk ${chunk.name} (explicitly excluded)`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = obfuscatorPlugin;
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "briq-vite-obfuscator-plugin",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "BSD-2-Clause",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"javascript-obfuscator": "^4.1.1"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue