提交 0d3894c7 作者: 毛细亚

init project

上级
.DS_Store
node_modules/
/dist/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/test/unit/coverage/
/test/e2e/reports/
selenium-debug.log
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
module.exports = {
simple: {
compact: true,
controlFlowFlattening: false,
deadCodeInjection: false,
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
identifierNamesGenerator: "hexadecimal",
log: false,
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
stringArray: true,
stringArrayEncoding: false,
stringArrayThreshold: 0.75,
unicodeEscapeSequence: false,
},
ordinary: {
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.75,
deadCodeInjection: true,
deadCodeInjectionThreshold: 0.4,
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
identifierNamesGenerator: "hexadecimal",
log: false,
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
stringArray: true,
stringArrayEncoding: "base64",
stringArrayThreshold: 0.75,
transformObjectKeys: true,
unicodeEscapeSequence: false,
},
highly: {
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
debugProtection: true,
debugProtectionInterval: true,
disableConsoleOutput: true,
identifierNamesGenerator: "hexadecimal",
log: false,
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
stringArray: true,
stringArrayEncoding: ["rc4"],
stringArrayThreshold: 1,
transformObjectKeys: true,
unicodeEscapeSequence: false,
},
};
{
"scripts": {
"s": "cross-env ENVIROMENT=simple webpack ",
"o": "cross-env ENVIROMENT=ordinary webpack ",
"h": "cross-env ENVIROMENT=highly webpack"
},
"dependencies": {
"webpack": "^5.64.0"
},
"devDependencies": {
"clean-webpack-plugin": "^4.0.0",
"cross-env": "^5.1.1",
"cross-port-killer": "^1.0.1",
"javascript-obfuscator": "^3.0.0",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack-cli": "^4.9.1",
"webpack-obfuscator": "^3.5.0"
}
}
## 关于webpackObfuscator压缩混淆代码
### 启动模式
```
num run s // 轻度混淆
npm run o // 中度混淆
npm run h // 重度混淆
```
## webpackObfuscator配置说明
### 1·高度混淆
```
/**
* 高度混淆
*
// 是否压缩代码
compact: true,
// 是否启用控制流扁平化(降低1.5倍的运行速度)
controlFlowFlattening: true,
// 应用概率;在较大的代码库中,建议降低此值,因为大量的控制流转换可能会增加代码的大小并降低代码的速度。
controlFlowFlatteningThreshold: 1,
// 随机的死代码块(增加了混淆代码的大小)
deadCodeInjection: true,
// 死代码块的影响概率
deadCodeInjectionThreshold: 1,
// 此选项几乎不可能使用开发者工具的控制台选项卡
debugProtection: true,
// 如果选中,则会在“控制台”选项卡上使用间隔强制调试模式,从而更难使用“开发人员工具”的其他功能。
debugProtectionInterval: true,
// 通过用空函数替换它们来禁用console.log,console.info,console.error和console.warn。这使得调试器的使用更加困难。
disableConsoleOutput: true,
// 标识符的混淆方式 hexadecimal(十六进制) mangled(短标识符)
identifierNamesGenerator: 'hexadecimal',
log: false,
// 是否启用全局变量和函数名称的混淆
renameGlobals: false,
// 通过固定和随机(在代码混淆时生成)的位置移动数组。这使得将删除的字符串的顺序与其原始位置相匹配变得更加困难。如果原始源代码不小,建议使用此选项,因为辅助函数可以引起注意。
rotateStringArray: true,
// 混淆后的代码,不能使用代码美化,同时需要配置 cpmpat:true;
selfDefending: true,
// 删除字符串文字并将它们放在一个特殊的数组中
stringArray: true,
stringArrayEncoding: 'rc4',
stringArrayThreshold: 1,
// 允许启用/禁用字符串转换为unicode转义序列。Unicode转义序列大大增加了代码大小,并且可以轻松地将字符串恢复为原始视图。建议仅对小型源代码启用此选项。
transformObjectKeys: true,
unicodeEscapeSequence: false
*/
```
### 2·中度混淆
```
/*
中度混淆
// 是否压缩代码
compact: true,
// 是否启用控制流扁平化(降低1.5倍的运行速度)
controlFlowFlattening: true,
// 应用概率;在较大的代码库中,建议降低此值,因为大量的控制流转换可能会增加代码的大小并降低代码的速度。
controlFlowFlatteningThreshold: 0.75,
// 随机的死代码块(增加了混淆代码的大小)
deadCodeInjection: true,
// 死代码块的影响概率
deadCodeInjectionThreshold: 0.4,
// 此选项几乎不可能使用开发者工具的控制台选项卡
debugProtection: false,
// 如果选中,则会在“控制台”选项卡上使用间隔强制调试模式,从而更难使用“开发人员工具”的其他功能。
debugProtectionInterval: false,
// 通过用空函数替换它们来禁用console.log,console.info,console.error和console.warn。这使得调试器的使用更加困难。
disableConsoleOutput: true,
// 标识符的混淆方式 hexadecimal(十六进制) mangled(短标识符)
identifierNamesGenerator: 'hexadecimal',
log: false,
// 是否启用全局变量和函数名称的混淆
renameGlobals: false,
// 通过固定和随机(在代码混淆时生成)的位置移动数组。这使得将删除的字符串的顺序与其原始位置相匹配变得更加困难。如果原始源代码不小,建议使用此选项,因为辅助函数可以引起注意。
rotateStringArray: true,
// 混淆后的代码,不能使用代码美化,同时需要配置 cpmpat:true;
selfDefending: true,
// 删除字符串文字并将它们放在一个特殊的数组中
stringArray: true,
stringArrayEncoding: 'base64',
stringArrayThreshold: 0.75,
transformObjectKeys: true,
// 允许启用/禁用字符串转换为unicode转义序列。Unicode转义序列大大增加了代码大小,并且可以轻松地将字符串恢复为原始视图。建议仅对小型源代码启用此选项。
unicodeEscapeSequence: false
*/
```
## 3.轻度混淆
```
/*
低混淆
// 是否压缩代码
compact: true,
// 是否启用控制流扁平化(降低1.5倍的运行速度)
controlFlowFlattening: false,
// 随机的死代码块(增加了混淆代码的大小)
deadCodeInjection: false,
// 此选项几乎不可能使用开发者工具的控制台选项卡
debugProtection: false,
// 如果选中,则会在“控制台”选项卡上使用间隔强制调试模式,从而更难使用“开发人员工具”的其他功能。
debugProtectionInterval: false,
// 通过用空函数替换它们来禁用console.log,console.info,console.error和console.warn。这使得调试器的使用更加困难。
disableConsoleOutput: true,
// 标识符的混淆方式 hexadecimal(十六进制) mangled(短标识符)
identifierNamesGenerator: 'hexadecimal',
log: false,
// 是否启用全局变量和函数名称的混淆
renameGlobals: false,
// 通过固定和随机(在代码混淆时生成)的位置移动数组。这使得将删除的字符串的顺序与其原始位置相匹配变得更加困难。如果原始源代码不小,建议使用此选项,因为辅助函数可以引起注意。
rotateStringArray: true,
// 混淆后的代码,不能使用代码美化,同时需要配置 cpmpat:true;
selfDefending: true,
// 删除字符串文字并将它们放在一个特殊的数组中
stringArray: true,
stringArrayEncoding: false,
stringArrayThreshold: 0.75,
// 允许启用/禁用字符串转换为unicode转义序列。Unicode转义序列大大增加了代码大小,并且可以轻松地将字符串恢复为原始视图。建议仅对小型源代码启用此选项。
unicodeEscapeSequence: false
*/
```
## 具体文档 点击[这里](https://blog.csdn.net/qq_31126175/article/details/86526237)
\ No newline at end of file
/**
* 封装微信小游戏的文件系统
*/
const wxFs = wx.getFileSystemManager();
const WX_ROOT = wx.env.USER_DATA_PATH + "/";
const { gameVersion } = "../config/config.js";
function walkFile(dirname, callback) {
const files = wxFs.readdirSync(dirname);
for (let f of files) {
const file = dirname + "/" + f;
const stat = wxFs.statSync(file);
if (stat.isDirectory()) {
walkFile(file, callback);
} else {
callback(file);
// console.log("当前文件被清理: " + file);
}
}
}
function walkDir(dirname, callback) {
// console.log(dirname + "执行 walkDir--");
const files = wxFs.readdirSync(dirname)
// console.log(dirname + "目录中有: ");
// console.log(files);
for (let f of files) {
const file = dirname + "/" + f;
try {
const stat = wxFs.statSync(file);
if (stat.isDirectory()) {
walkDir(file, callback);
callback(file)
}
} catch (e) {
console.warn(file + "不存在");
console.warn(e);
}
}
}
let fs_cache = {};
export const fs = {
/**
* 遍历删除文件夹
* removeRoot:根目录是否删除
*/
remove: (dirname, removeRoot) => {
if (!fs.existsSync(dirname))
return;
const globalDirname = WX_ROOT + dirname;
walkFile(globalDirname, (file) => {
wxFs.unlinkSync(file);
let p = file.replace(WX_ROOT, "");
p = path.normailze(p);
if (fs_cache[p]) {
fs_cache[p] = 0;
}
})
walkDir(globalDirname, (dir) => {
wxFs.rmdirSync(dir);
let p = dir.replace(WX_ROOT, "");
p = path.normailze(p);
if (fs_cache[p]) {
fs_cache[p] = 0;
}
})
if (removeRoot) {
try {
wxFs.rmdirSync(globalDirname, false);
} catch (e) {
console.warn("removeRoot fail");
console.error(e)
}
}
},
/**
* 检查文件是否存在
*/
existsSync: (p) => {
const cache = fs_cache[p];
if (cache == 0) {
return false;
} else if (cache == 1) {
return true;
} else {
try {
wxFs.accessSync(WX_ROOT + p);
p = path.normailze(p);
if (p) {
fs_cache[p] = 1;
}
return true;
} catch (e) {
p = path.normailze(p);
fs_cache[p] = 0;
return false;
}
}
},
writeSync: (p, content) => {
p = path.normailze(p);
fs_cache[p] = 1;
wxFs.writeFileSync(WX_ROOT + p, content);
},
readSync: (p, format) => {
format = format || 'utf-8';
return wxFs.readFileSync(WX_ROOT + p, format);
},
/**
* 创建文件夹
*/
mkdirsSync: (p) => {
// console.log(`mkdir: ${p}`)
const time1 = Date.now();
if (!fs.existsSync(p)) {
const dirs = p.split('/');
let current = "";
for (let i = 0; i < dirs.length; i++) {
const dir = dirs[i]
current += dir + "/";
if (!fs.existsSync(current)) {
let p = path.normailze(current);
fs_cache[p] = 1;
wxFs.mkdirSync(WX_ROOT + current)
}
}
} else {
return;
}
const time2 = Date.now() - time1;
// console.log(`mkdir: ${p} ${time2} ms`)
},
/**
* 解压 zip 文件
*/
unzip: (zipFilePath, targetPath) => {
zipFilePath = WX_ROOT + zipFilePath;
targetPath = WX_ROOT + targetPath;
return new Promise((resolve, reject) => {
//console.log(zipFilePath)
wxFs.unzip({
zipFilePath,
targetPath,
success: () => {
//console.log('success')
resolve();
},
fail(e) {
//console.log(e)
reject(e)
}
})
})
},
/////
setFsCache: (p, value) => {
fs_cache[p] = value;
}
}
export const path = {
dirname: (p) => {
const arr = p.split("/");
arr.pop();
return arr.join('/');
},
isRemotePath: (p) => {
return p.indexOf("http://") == 0 || p.indexOf("https://") == 0;
},
normailze: (p) => {
let arr = p.split("/");
let original = p.split("/");
for (let a of arr) {
if (a == '' || a == null) {
let index = original.indexOf(a);
original.splice(index, 1);
}
}
if (original.length > 0) {
return original.join('/');
}
},
// 根据key值表获取本地缓存路径
// 通过本函数可将网络地址转化为本地缓存地址
// 可通过编辑key值表来创建多个缓存路径
getLocalFilePath: (p) => {
const remoteFiles = path.remoteFiles;
const len = remoteFiles.length;
for(let i = 0; i < len; i++) {
const key = remoteFiles[i];
if (p.indexOf(key) >= 0) {
p = p.replace(key, path.localFiles[i]);
let nIndex = p.indexOf("?");
if (nIndex > -1) {
p = p.substr(0, nIndex);
}
return path.normailze(p);
}
}
//未设置key值,将按照地址名整理出资源路径,进行存储
if (p.indexOf(":") >= 0 || p.indexOf('#') >= 0 || p.indexOf('?') >= 0) {
p = p.replace(/[^a-z0-9.]/gi, "/");
}
return path.normailze(p);
},
// 获取微信的用户缓存地址
getWxUserPath: (p) => {
return WX_ROOT + p;
},
// 本地资源文件key值表
// 可按照网络资源地址分配本地地址,可修改
// 以下为示例,开发者可根据需要进行修改
remoteFiles: [
`${js_gameVars.qufuCdnServer}qufu_resource1/`, //区服资源
`${js_gameVars.qufuCdnServer}img/`, //区服资源
`${js_gameVars.qufuCdnServer}${gameVersion}/resource/`, //前端资源
`${js_gameVars.qufuCdnServer}${gameVersion}/`
],
localFiles: [
'temp_qufu3/', //区服资源
'temp_img2/', //区服资源
'temp_local/', //前端资源
'temp_root/'
]
}
\ No newline at end of file
const path = require('path')
const fs = require('fs') // 导入nodefs对象
const WebpackObfuscator = require('webpack-obfuscator');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const resolve = (p) => path.resolve(__dirname, "./", p)
const entryDir = resolve('src/js')
const outputDir = resolve("dist")
const Obfuscator = resolve('build/WebpackObfuscator.config.js')
const entryFiles = fs.readdirSync(entryDir) // 获取 js里面的文件
const env = process.env.ENVIROMENT.trim();
let ObfuscatorType = {};
let
entry = {},
output = {};
// 处理entry和output
function configInfi() {
entryFiles.forEach(dir => {
entry[dir] = path.resolve(__dirname, `${entryDir}/${dir}`)
output.filename = "js/[name].min[hash].js";
output.path = outputDir;
})
console.log('env',env)
if(env=='simple'){
ObfuscatorType = Obfuscator.simple
}else if(env=='ordinary'){
ObfuscatorType = Obfuscator.ordinary
}else if(env=='highly'){
ObfuscatorType = Obfuscator.highly
}else{
ObfuscatorType={}
}
}
configInfi()
module.exports={
mode:'development',
optimization:{
noEmitOnErrors: true, //编译时出现错误跳过
},
entry,
output,
plugins:[
new CleanWebpackPlugin(),
// new WebpackObfuscator (ObfuscatorType)
]
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论