提交 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,
},
};
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/js/index.js":
/*!*************************!*\
!*** ./src/js/index.js ***!
\*************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"fs\": () => (/* binding */ fs),\n/* harmony export */ \"path\": () => (/* binding */ path)\n/* harmony export */ });\n/**\n * 封装微信小游戏的文件系统\n */\n const wxFs = wx.getFileSystemManager();\n const WX_ROOT = wx.env.USER_DATA_PATH + \"/\";\n const { gameVersion } = \"../config/config.js\";\n \n function walkFile(dirname, callback) {\n const files = wxFs.readdirSync(dirname);\n \n for (let f of files) {\n const file = dirname + \"/\" + f;\n const stat = wxFs.statSync(file);\n if (stat.isDirectory()) {\n walkFile(file, callback);\n } else {\n callback(file);\n // console.log(\"当前文件被清理: \" + file);\n }\n }\n }\n \n \n function walkDir(dirname, callback) {\n // console.log(dirname + \"执行 walkDir--\");\n \n const files = wxFs.readdirSync(dirname)\n \n // console.log(dirname + \"目录中有: \");\n // console.log(files);\n \n for (let f of files) {\n const file = dirname + \"/\" + f;\n \n try {\n const stat = wxFs.statSync(file);\n if (stat.isDirectory()) {\n walkDir(file, callback);\n callback(file)\n }\n } catch (e) {\n console.warn(file + \"不存在\");\n console.warn(e);\n }\n }\n }\n \n let fs_cache = {};\n \n const fs = {\n \n /**\n * 遍历删除文件夹\n * removeRoot:根目录是否删除\n */\n remove: (dirname, removeRoot) => {\n if (!fs.existsSync(dirname))\n return;\n const globalDirname = WX_ROOT + dirname;\n walkFile(globalDirname, (file) => {\n wxFs.unlinkSync(file);\n let p = file.replace(WX_ROOT, \"\");\n p = path.normailze(p);\n if (fs_cache[p]) {\n fs_cache[p] = 0;\n }\n })\n walkDir(globalDirname, (dir) => {\n wxFs.rmdirSync(dir);\n let p = dir.replace(WX_ROOT, \"\");\n p = path.normailze(p);\n if (fs_cache[p]) {\n fs_cache[p] = 0;\n }\n })\n if (removeRoot) {\n try {\n wxFs.rmdirSync(globalDirname, false);\n } catch (e) {\n console.warn(\"removeRoot fail\");\n console.error(e)\n }\n }\n },\n \n /**\n * 检查文件是否存在\n */\n existsSync: (p) => {\n const cache = fs_cache[p];\n if (cache == 0) {\n return false;\n } else if (cache == 1) {\n return true;\n } else {\n try {\n wxFs.accessSync(WX_ROOT + p);\n p = path.normailze(p);\n if (p) {\n fs_cache[p] = 1;\n }\n return true;\n } catch (e) {\n p = path.normailze(p);\n fs_cache[p] = 0;\n return false;\n }\n }\n \n },\n \n \n writeSync: (p, content) => {\n p = path.normailze(p);\n fs_cache[p] = 1;\n wxFs.writeFileSync(WX_ROOT + p, content);\n },\n \n readSync: (p, format) => {\n format = format || 'utf-8';\n return wxFs.readFileSync(WX_ROOT + p, format);\n },\n \n /**\n * 创建文件夹\n */\n mkdirsSync: (p) => {\n // console.log(`mkdir: ${p}`)\n const time1 = Date.now();\n \n if (!fs.existsSync(p)) {\n const dirs = p.split('/');\n let current = \"\";\n for (let i = 0; i < dirs.length; i++) {\n const dir = dirs[i]\n current += dir + \"/\";\n if (!fs.existsSync(current)) {\n let p = path.normailze(current);\n fs_cache[p] = 1;\n wxFs.mkdirSync(WX_ROOT + current)\n \n }\n }\n } else {\n return;\n }\n const time2 = Date.now() - time1;\n // console.log(`mkdir: ${p} ${time2} ms`)\n },\n \n \n /**\n * 解压 zip 文件\n */\n unzip: (zipFilePath, targetPath) => {\n zipFilePath = WX_ROOT + zipFilePath;\n targetPath = WX_ROOT + targetPath;\n return new Promise((resolve, reject) => {\n //console.log(zipFilePath)\n wxFs.unzip({\n zipFilePath,\n targetPath,\n success: () => {\n //console.log('success')\n resolve();\n },\n fail(e) {\n //console.log(e)\n reject(e)\n }\n })\n })\n },\n /////\n setFsCache: (p, value) => {\n fs_cache[p] = value;\n }\n }\n \n const path = {\n \n dirname: (p) => {\n const arr = p.split(\"/\");\n arr.pop();\n return arr.join('/');\n },\n \n \n isRemotePath: (p) => {\n return p.indexOf(\"http://\") == 0 || p.indexOf(\"https://\") == 0;\n },\n \n normailze: (p) => {\n let arr = p.split(\"/\");\n let original = p.split(\"/\");\n for (let a of arr) {\n if (a == '' || a == null) {\n let index = original.indexOf(a);\n original.splice(index, 1);\n }\n }\n if (original.length > 0) {\n return original.join('/');\n }\n },\n // 根据key值表获取本地缓存路径\n // 通过本函数可将网络地址转化为本地缓存地址\n // 可通过编辑key值表来创建多个缓存路径\n getLocalFilePath: (p) => {\n const remoteFiles = path.remoteFiles;\n const len = remoteFiles.length;\n \n for(let i = 0; i < len; i++) {\n const key = remoteFiles[i];\n if (p.indexOf(key) >= 0) {\n p = p.replace(key, path.localFiles[i]);\n \n let nIndex = p.indexOf(\"?\");\n if (nIndex > -1) {\n p = p.substr(0, nIndex);\n }\n \n return path.normailze(p);\n }\n }\n \n //未设置key值,将按照地址名整理出资源路径,进行存储\n if (p.indexOf(\":\") >= 0 || p.indexOf('#') >= 0 || p.indexOf('?') >= 0) {\n p = p.replace(/[^a-z0-9.]/gi, \"/\");\n }\n return path.normailze(p);\n },\n // 获取微信的用户缓存地址\n getWxUserPath: (p) => {\n return WX_ROOT + p;\n },\n // 本地资源文件key值表\n // 可按照网络资源地址分配本地地址,可修改\n // 以下为示例,开发者可根据需要进行修改\n remoteFiles: [\n `${js_gameVars.qufuCdnServer}qufu_resource1/`, //区服资源\n `${js_gameVars.qufuCdnServer}img/`, //区服资源\n `${js_gameVars.qufuCdnServer}${gameVersion}/resource/`, //前端资源\n `${js_gameVars.qufuCdnServer}${gameVersion}/`\n ],\n localFiles: [\n 'temp_qufu3/', //区服资源\n 'temp_img2/', //区服资源\n 'temp_local/', //前端资源\n 'temp_root/'\n ]\n }\n \n\n//# sourceURL=webpack:///./src/js/index.js?");
/***/ })
/******/ });
/************************************************************************/
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = {};
/******/ __webpack_modules__["./src/js/index.js"](0, __webpack_exports__, __webpack_require__);
/******/
/******/ })()
;
\ No newline at end of file
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/js/index2.js":
/*!**************************!*\
!*** ./src/js/index2.js ***!
\**************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"fs\": () => (/* binding */ fs),\n/* harmony export */ \"path\": () => (/* binding */ path)\n/* harmony export */ });\n/**\n * 封装微信小游戏的文件系统\n */\n const wxFs = wx.getFileSystemManager();\n const WX_ROOT = wx.env.USER_DATA_PATH + \"/\";\n const { gameVersion } = \"../config/config.js\";\n \n function walkFile(dirname, callback) {\n const files = wxFs.readdirSync(dirname);\n \n for (let f of files) {\n const file = dirname + \"/\" + f;\n const stat = wxFs.statSync(file);\n if (stat.isDirectory()) {\n walkFile(file, callback);\n } else {\n callback(file);\n // console.log(\"当前文件被清理: \" + file);\n }\n }\n }\n \n \n function walkDir(dirname, callback) {\n // console.log(dirname + \"执行 walkDir--\");\n \n const files = wxFs.readdirSync(dirname)\n \n // console.log(dirname + \"目录中有: \");\n // console.log(files);\n \n for (let f of files) {\n const file = dirname + \"/\" + f;\n \n try {\n const stat = wxFs.statSync(file);\n if (stat.isDirectory()) {\n walkDir(file, callback);\n callback(file)\n }\n } catch (e) {\n console.warn(file + \"不存在\");\n console.warn(e);\n }\n }\n }\n \n let fs_cache = {};\n \n const fs = {\n \n /**\n * 遍历删除文件夹\n * removeRoot:根目录是否删除\n */\n remove: (dirname, removeRoot) => {\n if (!fs.existsSync(dirname))\n return;\n const globalDirname = WX_ROOT + dirname;\n walkFile(globalDirname, (file) => {\n wxFs.unlinkSync(file);\n let p = file.replace(WX_ROOT, \"\");\n p = path.normailze(p);\n if (fs_cache[p]) {\n fs_cache[p] = 0;\n }\n })\n walkDir(globalDirname, (dir) => {\n wxFs.rmdirSync(dir);\n let p = dir.replace(WX_ROOT, \"\");\n p = path.normailze(p);\n if (fs_cache[p]) {\n fs_cache[p] = 0;\n }\n })\n if (removeRoot) {\n try {\n wxFs.rmdirSync(globalDirname, false);\n } catch (e) {\n console.warn(\"removeRoot fail\");\n console.error(e)\n }\n }\n },\n \n /**\n * 检查文件是否存在\n */\n existsSync: (p) => {\n const cache = fs_cache[p];\n if (cache == 0) {\n return false;\n } else if (cache == 1) {\n return true;\n } else {\n try {\n wxFs.accessSync(WX_ROOT + p);\n p = path.normailze(p);\n if (p) {\n fs_cache[p] = 1;\n }\n return true;\n } catch (e) {\n p = path.normailze(p);\n fs_cache[p] = 0;\n return false;\n }\n }\n \n },\n \n \n writeSync: (p, content) => {\n p = path.normailze(p);\n fs_cache[p] = 1;\n wxFs.writeFileSync(WX_ROOT + p, content);\n },\n \n readSync: (p, format) => {\n format = format || 'utf-8';\n return wxFs.readFileSync(WX_ROOT + p, format);\n },\n \n /**\n * 创建文件夹\n */\n mkdirsSync: (p) => {\n // console.log(`mkdir: ${p}`)\n const time1 = Date.now();\n \n if (!fs.existsSync(p)) {\n const dirs = p.split('/');\n let current = \"\";\n for (let i = 0; i < dirs.length; i++) {\n const dir = dirs[i]\n current += dir + \"/\";\n if (!fs.existsSync(current)) {\n let p = path.normailze(current);\n fs_cache[p] = 1;\n wxFs.mkdirSync(WX_ROOT + current)\n \n }\n }\n } else {\n return;\n }\n const time2 = Date.now() - time1;\n // console.log(`mkdir: ${p} ${time2} ms`)\n },\n \n \n /**\n * 解压 zip 文件\n */\n unzip: (zipFilePath, targetPath) => {\n zipFilePath = WX_ROOT + zipFilePath;\n targetPath = WX_ROOT + targetPath;\n return new Promise((resolve, reject) => {\n //console.log(zipFilePath)\n wxFs.unzip({\n zipFilePath,\n targetPath,\n success: () => {\n //console.log('success')\n resolve();\n },\n fail(e) {\n //console.log(e)\n reject(e)\n }\n })\n })\n },\n /////\n setFsCache: (p, value) => {\n fs_cache[p] = value;\n }\n }\n \n const path = {\n \n dirname: (p) => {\n const arr = p.split(\"/\");\n arr.pop();\n return arr.join('/');\n },\n \n \n isRemotePath: (p) => {\n return p.indexOf(\"http://\") == 0 || p.indexOf(\"https://\") == 0;\n },\n \n normailze: (p) => {\n let arr = p.split(\"/\");\n let original = p.split(\"/\");\n for (let a of arr) {\n if (a == '' || a == null) {\n let index = original.indexOf(a);\n original.splice(index, 1);\n }\n }\n if (original.length > 0) {\n return original.join('/');\n }\n },\n // 根据key值表获取本地缓存路径\n // 通过本函数可将网络地址转化为本地缓存地址\n // 可通过编辑key值表来创建多个缓存路径\n getLocalFilePath: (p) => {\n const remoteFiles = path.remoteFiles;\n const len = remoteFiles.length;\n \n for(let i = 0; i < len; i++) {\n const key = remoteFiles[i];\n if (p.indexOf(key) >= 0) {\n p = p.replace(key, path.localFiles[i]);\n \n let nIndex = p.indexOf(\"?\");\n if (nIndex > -1) {\n p = p.substr(0, nIndex);\n }\n \n return path.normailze(p);\n }\n }\n \n //未设置key值,将按照地址名整理出资源路径,进行存储\n if (p.indexOf(\":\") >= 0 || p.indexOf('#') >= 0 || p.indexOf('?') >= 0) {\n p = p.replace(/[^a-z0-9.]/gi, \"/\");\n }\n return path.normailze(p);\n },\n // 获取微信的用户缓存地址\n getWxUserPath: (p) => {\n return WX_ROOT + p;\n },\n // 本地资源文件key值表\n // 可按照网络资源地址分配本地地址,可修改\n // 以下为示例,开发者可根据需要进行修改\n remoteFiles: [\n `${js_gameVars.qufuCdnServer}qufu_resource1/`, //区服资源\n `${js_gameVars.qufuCdnServer}img/`, //区服资源\n `${js_gameVars.qufuCdnServer}${gameVersion}/resource/`, //前端资源\n `${js_gameVars.qufuCdnServer}${gameVersion}/`\n ],\n localFiles: [\n 'temp_qufu3/', //区服资源\n 'temp_img2/', //区服资源\n 'temp_local/', //前端资源\n 'temp_root/'\n ]\n }\n \n\n//# sourceURL=webpack:///./src/js/index2.js?");
/***/ })
/******/ });
/************************************************************************/
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = {};
/******/ __webpack_modules__["./src/js/index2.js"](0, __webpack_exports__, __webpack_require__);
/******/
/******/ })()
;
\ No newline at end of file
{
"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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论