提交 cf7dc5f0 作者: 毛细亚

更新代码

上级 0d3894c7
module.exports = { module.exports = {
simple: { simple: {
compact: true, compact: true,
controlFlowFlattening: false, deadCodeInjection: true,
deadCodeInjection: false, deadCodeInjectionThreshold: 1,
debugProtection: false, // controlFlowFlattening: false,
debugProtectionInterval: false, // deadCodeInjection: false,
disableConsoleOutput: true, // debugProtection: false,
identifierNamesGenerator: "hexadecimal", // debugProtectionInterval: false,
log: false, // disableConsoleOutput: true,
renameGlobals: false, // identifierNamesGenerator: "hexadecimal",
rotateStringArray: true, // log: false,
selfDefending: true, // renameGlobals: false,
stringArray: true, // rotateStringArray: true,
stringArrayEncoding: false, // selfDefending: true,
stringArrayThreshold: 0.75, // stringArray: true,
unicodeEscapeSequence: false, // stringArrayEncoding: false,
// stringArrayThreshold: 0.75,
// unicodeEscapeSequence: false,
}, },
ordinary: { ordinary: {
compact: true, compact: true,
......
const fileutil = require('./file-util');
const path = fileutil.path;
const fs = fileutil.fs;
const WXFS = wx.getFileSystemManager();
class BinaryProcessor {
onLoadStart(host, resource) {
const {
root,
url
} = resource;
return new Promise((resolve, reject) => {
let xhrURL = url.indexOf('://') >= 0 ? url : root + url;
RES['getVirtualUrl']?xhrURL = RES['getVirtualUrl'](xhrURL):'';
if (!path.isRemotePath(xhrURL)&&true) {
//本地加载
try {
const content = WXFS.readFileSync(xhrURL);
resolve(content);
} catch (e) {
resolve(null);
}
return;
}
if (needCache(xhrURL)) {
//缓存加载
const targetFilename = path.getLocalFilePath(xhrURL);
if (fs.existsSync(targetFilename)) {
//缓存命中
let data = WXFS.readFileSync(path.getWxUserPath(targetFilename));
resolve(data);
return;
}
loadBinary(xhrURL).then((content) => {
//写入本地
const dirname = path.dirname(targetFilename);
fs.mkdirsSync(dirname);
fs.writeSync(targetFilename, content);
let needRead = needReadFile();
if (needRead) {
content = WXFS.readFileSync(path.getWxUserPath(targetFilename));
}
resolve(content);
}).catch((e) => {
reject(e);
});
} else {
//不用缓存直接加载
loadBinary(xhrURL).then((content) => {
resolve(content);
}).catch((e) => {
reject(e);
});
}
});
}
onRemoveStart(host, resource) {
return Promise.resolve();
}
}
let wxSystemInfo;
function needReadFile() {
if (!wxSystemInfo) {
wxSystemInfo = wx.getSystemInfoSync();
}
let sdkVersion = wxSystemInfo.SDKVersion;
let platform = wxSystemInfo.system.split(" ").shift();
return (sdkVersion <= '2.2.3') && (platform == 'iOS');
}
function loadBinary(xhrURL) {
return new Promise((resolve, reject) => {
wx.request({
url: xhrURL,
method: 'get',
responseType: 'arraybuffer',
success: function success(_ref) {
resolve(_ref.data)
},
fail: function fail(_ref2) {
const error = new RES.ResourceManagerError(1001, xhrURL);
console.error('load binary error', xhrURL);
reject(error)
}
});
});
}
/**
* 由于微信小游戏限制只有50M的资源可以本地存储,
* 所以开发者应根据URL进行判断,将特定资源进行本地缓存
*/
function needCache(url) {
if (url.indexOf(`map${js_gameVars.resVersion}`) >= 0) {
return true;
} else {
return false;
}
}
const processor = new BinaryProcessor();
RES.processor.map("bin", processor);
/*
* 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
...@@ -8,11 +8,17 @@ ...@@ -8,11 +8,17 @@
"webpack": "^5.64.0" "webpack": "^5.64.0"
}, },
"devDependencies": { "devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"clean-webpack-plugin": "^4.0.0", "clean-webpack-plugin": "^4.0.0",
"cross-env": "^5.1.1", "cross-env": "^5.1.1",
"cross-port-killer": "^1.0.1", "cross-port-killer": "^1.0.1",
"javascript-obfuscator": "^3.0.0", "javascript-obfuscator": "^3.0.0",
"uglifyjs-webpack-plugin": "^2.2.0", "uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^5.64.0",
"webpack-cli": "^4.9.1", "webpack-cli": "^4.9.1",
"webpack-obfuscator": "^3.5.0" "webpack-obfuscator": "^3.5.0"
} }
......
let obj = {name:'小明',age:'12',action(){
console.log('[ 在上学 ]')
}}
obj.action()
\ 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 path = require('path')
const fs = require('fs') // 导入nodefs对象 const fs = require('fs') // 导入nodefs对象
const webpack = require('webpack')
const UglifyjsPlugin = require('uglifyjs-webpack-plugin')
const WebpackObfuscator = require('webpack-obfuscator'); const WebpackObfuscator = require('webpack-obfuscator');
const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const resolve = (p) => path.resolve(__dirname, "./", p) const resolve = (p) => path.resolve(__dirname, "./", p)
...@@ -35,14 +37,28 @@ function configInfi() { ...@@ -35,14 +37,28 @@ function configInfi() {
configInfi() configInfi()
module.exports={ module.exports={
mode:'development', mode:'development',
optimization:{ optimization: {
noEmitOnErrors: true, //编译时出现错误跳过 noEmitOnErrors: true,
}, minimizer: [
new UglifyjsPlugin({
// 使用缓存
cache: true
}),
]
},
entry, entry,
output, output,
plugins:[ plugins:[
new CleanWebpackPlugin(),
// new WebpackObfuscator (ObfuscatorType) new webpack.NoEmitOnErrorsPlugin(),
new CleanWebpackPlugin( {
root: resolve(""), // 设置根节点
verbose: true, //开启在控制台输出信息
dry: false,
}),
new WebpackObfuscator (ObfuscatorType),
// new webpack.IgnorePlugin(/\.\/locale/, /moment/)
] ]
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论