mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40:01 -04:00
update rspack
This commit is contained in:
parent
cb395552c8
commit
fc8738b239
3 changed files with 54 additions and 25 deletions
|
@ -1,8 +1,10 @@
|
|||
import { defineConfig } from "@rspack/cli";
|
||||
import { rspack } from "@rspack/core";
|
||||
// import { RsdoctorRspackPlugin } from "@rsdoctor/rspack-plugin";
|
||||
import { RsdoctorRspackPlugin } from "@rsdoctor/rspack-plugin";
|
||||
import { join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import obfuscator from "javascript-obfuscator";
|
||||
const { obfuscate } = obfuscator;
|
||||
|
||||
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||
|
||||
|
@ -14,7 +16,6 @@ export default defineConfig({
|
|||
worker: join(__dirname, "src/worker/index.ts"),
|
||||
thread: join(__dirname, "src/thread/thread.ts"),
|
||||
client: join(__dirname, "src/client/index.ts"),
|
||||
config: join(__dirname, "src/scramjet.config.ts"),
|
||||
codecs: join(__dirname, "src/codecs/index.ts"),
|
||||
controller: join(__dirname, "src/controller/index.ts"),
|
||||
},
|
||||
|
@ -51,6 +52,9 @@ export default defineConfig({
|
|||
},
|
||||
},
|
||||
},
|
||||
optimization: {
|
||||
minimize: process.env.OBFUSCATE === "true",
|
||||
},
|
||||
output: {
|
||||
filename: "scramjet.[name].js",
|
||||
path: join(__dirname, "dist"),
|
||||
|
@ -63,12 +67,50 @@ export default defineConfig({
|
|||
dbg: [join(__dirname, "src/log.ts"), "default"],
|
||||
Function: [join(__dirname, "src/snapshot.ts"), "Function"],
|
||||
}),
|
||||
process.env.OBFUSCATE === "true" && {
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("GyatPlugin", (compilation) => {
|
||||
compilation.hooks.processAssets.tap(
|
||||
{
|
||||
name: "GyatPlugin",
|
||||
stage: compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
|
||||
},
|
||||
(assets) => {
|
||||
for (const asset in assets) {
|
||||
// inject code
|
||||
compilation.updateAsset(asset, (source) => {
|
||||
return {
|
||||
source: () => {
|
||||
return obfuscate(source.source(), {
|
||||
compact: true,
|
||||
controlFlowFlattening: true,
|
||||
controlFlowFlatteningThreshold: 1,
|
||||
numbersToExpressions: true,
|
||||
simplify: true,
|
||||
deadCodeInjection: true,
|
||||
selfDefending: true,
|
||||
renameGlobals: true,
|
||||
transformObjectKeys: true,
|
||||
stringArrayShuffle: true,
|
||||
splitStrings: true,
|
||||
stringArrayThreshold: 1,
|
||||
domainLock: ["localhost", process.env.DOMAIN],
|
||||
}).getObfuscatedCode();
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
// new RsdoctorRspackPlugin({
|
||||
// supports: {
|
||||
// parseBundle: true,
|
||||
// banner: true
|
||||
// }
|
||||
// })
|
||||
// supports: {
|
||||
// parseBundle: true,
|
||||
// banner: true,
|
||||
// },
|
||||
// }),
|
||||
],
|
||||
target: "webworker",
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue