From 15230cdd2f9470bd91fca3a05479b56652c5e371 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Mon, 25 Jul 2022 15:17:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=20xml-loader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/loaders/wxml-loader.js | 47 +++++++++++++++++++---------------- config/mp/webpack.config.js | 8 ++++++ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/config/loaders/wxml-loader.js b/config/loaders/wxml-loader.js index 41070fa..680d4e4 100644 --- a/config/loaders/wxml-loader.js +++ b/config/loaders/wxml-loader.js @@ -133,11 +133,10 @@ function getAppJson(context) { } module.exports = async function (content) { - // loader的缓存功能 - // this.cacheable && this.cacheable(); - const options = this.getOptions() || {}; //获取配置参数 - const { context: projectContext } = options; // context 本项目路径 + const { context: projectContext, cacheDirectory = true } = options; // context 本项目路径 + // loader的缓存功能 + this.cacheable && this.cacheable(cacheDirectory); const callback = this.async(); const { options: webpackLegacyOptions, @@ -186,7 +185,6 @@ module.exports = async function (content) { `` + source; } - } // 注入全局message组件 if (/pages/.test(context)) { @@ -196,9 +194,7 @@ module.exports = async function (content) { appJson.usingComponents && appJson.usingComponents[oakMessage] ) { - source = - source + - `\n <${oakMessage}>`; + source = source + `\n <${oakMessage}>`; } } @@ -254,8 +250,7 @@ module.exports = async function (content) { } else { node.setAttribute('focus', `{{!!oakFocused.${oakValue}}}`); } - } - else if (node.hasAttribute('oak:path')) { + } else if (node.hasAttribute('oak:path')) { // oak:path声明的属性加上oakPath和oakParent const oakValue = node.getAttribute('oak:path'); node.removeAttribute('oak:path'); @@ -279,21 +274,29 @@ module.exports = async function (content) { let newVal = ''; valArr.forEach((ele, index) => { if (existsT(ele)) { - const head = ele.substring(0, ele.indexOf("i18n.t(") + 7); + const head = ele.substring( + 0, + ele.indexOf('i18n.t(') + 7 + ); let argsStr = ele.substring(ele.indexOf('i18n.t(') + 7); - argsStr = argsStr.substring(0, argsStr.indexOf(')')); + argsStr = argsStr.substring(0, argsStr.indexOf(')')); const end = ele.substring(ele.indexOf(')')); - const arguments = argsStr.split(',').filter(ele2 => !!ele2); + const arguments = argsStr + .split(',') + .filter((ele2) => !!ele2); arguments && - arguments.forEach((nodeVal, index) => { - if (index === 0 && nodeVal.indexOf(':') === -1) { - arguments.splice( - index, - 1, - `'${ns}:' + ` + nodeVal - ); - } - }); + arguments.forEach((nodeVal, index) => { + if ( + index === 0 && + nodeVal.indexOf(':') === -1 + ) { + arguments.splice( + index, + 1, + `'${ns}:' + ` + nodeVal + ); + } + }); newVal += head + arguments.join(',') + diff --git a/config/mp/webpack.config.js b/config/mp/webpack.config.js index 4c8d25e..f8513ee 100644 --- a/config/mp/webpack.config.js +++ b/config/mp/webpack.config.js @@ -279,6 +279,8 @@ module.exports = function (webpackEnv) { loader: 'babel-loader', options: { plugins: [oakI18nPlugin], + //开启缓存 + // cacheDirectory: false, }, }, { @@ -292,6 +294,9 @@ module.exports = function (webpackEnv) { loader: 'babel-loader', options: { plugins: [oakI18nPlugin], + //开启缓存 + // cacheDirectory: false, + // presets: ['@babel/preset-env'], }, }, { @@ -326,6 +331,7 @@ module.exports = function (webpackEnv) { loader: 'wxml-loader', options: { context: paths.appSrc, + cacheDirectory: false, }, }, ], @@ -341,6 +347,7 @@ module.exports = function (webpackEnv) { loader: 'wxml-loader', options: { context: paths.appSrc, + cacheDirectory: false, }, }, ], @@ -355,6 +362,7 @@ module.exports = function (webpackEnv) { loader: 'wxml-loader', options: { context: paths.appSrc, + cacheDirectory: false, }, }, ],