This commit is contained in:
hackrobot
2025-04-02 06:35:01 -05:00
parent 77dfe5d60b
commit b19329182b
4 changed files with 304 additions and 58 deletions

View File

@@ -1,6 +1,7 @@
import path from "path";
// const { GenerateSW } = require("workbox-webpack-plugin");
const WebpackObfuscator = require("webpack-obfuscator");
const config = {
projectName: "cityh5",
@@ -37,43 +38,25 @@ const config = {
chunkFilename: "static/css/[name].[contenthash:8].css",
},
]);
// if (
// process.env.NODE_ENV === "production" &&
// !chain.plugins.has("workbox")
// ) {
// chain.plugin("workbox").use(GenerateSW, [
// {
// clientsClaim: true,
// skipWaiting: true,
// maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // 10MB
// runtimeCaching: [
// {
// urlPattern: /.*\.(?:png|jpg|jpeg|svg|gif|ico)/,
// handler: "CacheFirst",
// options: {
// cacheName: "images-cache",
// expiration: {
// maxEntries: 50,
// maxAgeSeconds: 30 * 24 * 60 * 60,
// },
// },
// },
// {
// urlPattern: /.*\.(?:js|css)/,
// handler: "StaleWhileRevalidate",
// options: {
// cacheName: "static-resources",
// expiration: {
// maxEntries: 50,
// maxAgeSeconds: 7 * 24 * 60 * 60,
// },
// },
// },
// ],
// },
// ]);
// }
// js代码混淆
chain.plugin("obfuscator").use(WebpackObfuscator, [
{
rotateStringArray: true,
stringArray: true,
stringArrayThreshold: 0.5, // 降低比例,提高速度
compact: true,
controlFlowFlattening: false, // 关闭,提高速度
deadCodeInjection: false, // 关闭,提高速度
debugProtection: false,
disableConsoleOutput: true,
selfDefending: false, // 关闭,提高速度
simplify: true, // 开启简化,提高性能
// 禁用对 async/await 的转换
target: "browser", // 或设置为适合目标环境的 ECMAScript 版本
disableOptimizations: true, // 禁用某些优化来避免处理 async/await
},
["**/*.js", "!node_modules/**"], // 避免对 node_modules 进行混淆
]);
chain.module
.rule("markdown")
.test(/\.md$/)