mirror of
https://github.com/mainnika/a-quest.git
synced 2026-06-13 17:53:33 +00:00
parcel bundler
This commit is contained in:
@@ -33,3 +33,5 @@ task2-backend/task2-backend
|
|||||||
task3-backend/task3-backend
|
task3-backend/task3-backend
|
||||||
|
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
|
build/
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
const Bundler = require('parcel-bundler');
|
||||||
|
const Path = require('path');
|
||||||
|
const FS = require('fs');
|
||||||
|
const Obfuscator = require("javascript-obfuscator");
|
||||||
|
|
||||||
|
const module_name = process.argv[2];
|
||||||
|
|
||||||
|
if (!module_name) {
|
||||||
|
throw new Error('no module name');
|
||||||
|
}
|
||||||
|
|
||||||
|
const entryFiles = Path.join(__dirname, module_name, './index.html');
|
||||||
|
const outDir = Path.join(__dirname, 'build', module_name);
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
outDir: outDir,
|
||||||
|
cache: false,
|
||||||
|
watch: false,
|
||||||
|
minify: true,
|
||||||
|
hmr: false,
|
||||||
|
sourceMaps: false,
|
||||||
|
detailedReport: true,
|
||||||
|
contentHash: true,
|
||||||
|
production: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const obfuscation = { controlFlowFlattening: true };
|
||||||
|
|
||||||
|
(async function () {
|
||||||
|
const bundler = new Bundler(entryFiles, options);
|
||||||
|
|
||||||
|
bundler.bundle();
|
||||||
|
|
||||||
|
bundler.on('bundled', async (bundle) => {
|
||||||
|
|
||||||
|
for (let result of bundle.childBundles) {
|
||||||
|
if (result.type != 'js') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise
|
||||||
|
.resolve()
|
||||||
|
.then(() => new Promise((res, rej) =>
|
||||||
|
FS.readFile(result.name, { encoding: 'utf8' }, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
return rej(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
res(Obfuscator.obfuscate(data, obfuscation).getObfuscatedCode())
|
||||||
|
})))
|
||||||
|
.then((obfuscated) => new Promise((res, rej) =>
|
||||||
|
FS.writeFile(result.name, obfuscated, (err) => {
|
||||||
|
if (err) {
|
||||||
|
return rej(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
res();
|
||||||
|
})))
|
||||||
|
.then(() => console.log(`→ ${result.name} obfuscated`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
Generated
-7055
File diff suppressed because it is too large
Load Diff
+6
-2
@@ -4,7 +4,8 @@
|
|||||||
"description": "adm-quest",
|
"description": "adm-quest",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf build dist .cache",
|
"clean": "rimraf build dist .cache",
|
||||||
"build-task1": "parcel build -d build/task1 task1/index.html"
|
"build-task1": "node make task1",
|
||||||
|
"build-task2": "node make task2"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -17,8 +18,11 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/mainnika/a-quest#readme",
|
"homepage": "https://github.com/mainnika/a-quest#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"bootstrap": "^4.4.1",
|
||||||
|
"javascript-obfuscator": "^0.20.4",
|
||||||
|
"jquery": "^3.4.1",
|
||||||
"parcel-bundler": "^1.12.4",
|
"parcel-bundler": "^1.12.4",
|
||||||
"parcel-plugin-obfuscate": "^1.0.0",
|
"popper.js": "^1.16.0",
|
||||||
"rimraf": "^3.0.0"
|
"rimraf": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user