feat: 禁止缓存与js混淆

This commit is contained in:
hackrobot
2025-04-03 22:11:56 -05:00
parent 9b5299cae1
commit e527889827
4 changed files with 525 additions and 69 deletions

View File

@@ -1,4 +1,6 @@
import path from "path";
const WebpackObfuscator = require("webpack-obfuscator");
const config = {
projectName: "cityh5",
date: "2023-12-2",
@@ -21,32 +23,43 @@ const config = {
cache: {
enable: false, // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
},
mini: {
postcss: {
pxtransform: {
enable: true,
config: {},
},
url: {
enable: true,
config: {
limit: 1024, // 设定转换尺寸上限
},
},
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: "module", // 转换模式,取值为 global/module
generateScopedName: "[name]__[local]___[hash:base64:5]",
},
},
},
},
alias: {
"@": path.resolve(__dirname, "..", "src"),
},
h5: {
webpackChain(chain) {
chain.output.filename("static/js/[name].[contenthash:8].js");
chain.output.chunkFilename("static/js/[name].[contenthash:8].js");
chain
.plugin("MiniCssExtractPlugin")
.use(require("mini-css-extract-plugin"), [
{
filename: "static/css/[name].[contenthash:8].css",
chunkFilename: "static/css/[name].[contenthash:8].css",
},
]);
if (process.env.NODE_ENV === "production") {
// 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$/)