From 979b0c29873ccba585e31d2b7179cb4490c7be2f Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Fri, 29 Oct 2021 17:15:50 +0800 Subject: [PATCH] =?UTF-8?q?chore(mp):=20=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=88=B0=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-mp-alipay/lib/uni.config.js | 12 +++++------- packages/uni-mp-weixin/lib/uni.config.js | 12 +++++------- packages/vue-cli-plugin-uni/lib/mp/index.js | 14 +++----------- .../webpack-uni-mp-loader/lib/plugin/index-new.js | 3 ++- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/packages/uni-mp-alipay/lib/uni.config.js b/packages/uni-mp-alipay/lib/uni.config.js index b1b78060f..3d03fb09d 100644 --- a/packages/uni-mp-alipay/lib/uni.config.js +++ b/packages/uni-mp-alipay/lib/uni.config.js @@ -25,14 +25,12 @@ module.exports = { copyOptions.push('uni_modules/' + module + '/mycomponents') }) - JSON.parse(process.env.UNI_MP_PLUGIN_EXPORT) - .concat(process.env.UNI_MP_PLUGIN ? 'plugin.json' : undefined) - .forEach(fileName => { - fileName && copyOptions.push({ - from: path.resolve(process.env.UNI_INPUT_DIR, fileName), - transform: content => fileName === 'plugin.json' ? JSON.stringify(parseJson(content.toString(), true)) : content - }) + if (process.env.UNI_MP_PLUGIN) { + copyOptions.push({ + from: path.resolve(process.env.UNI_INPUT_DIR, 'plugin.json'), + transform: content => JSON.stringify(parseJson(content.toString(), true)) }) + } return copyOptions } diff --git a/packages/uni-mp-weixin/lib/uni.config.js b/packages/uni-mp-weixin/lib/uni.config.js index c6ef0d0a8..8ffbc50ce 100644 --- a/packages/uni-mp-weixin/lib/uni.config.js +++ b/packages/uni-mp-weixin/lib/uni.config.js @@ -32,14 +32,12 @@ module.exports = { 'functional-pages' ] - JSON.parse(process.env.UNI_MP_PLUGIN_EXPORT) - .concat(process.env.UNI_MP_PLUGIN ? 'plugin.json' : undefined) - .forEach(fileName => { - fileName && copyOptions.push({ - from: path.resolve(process.env.UNI_INPUT_DIR, fileName), - transform: content => fileName === 'plugin.json' ? JSON.stringify(parseJson(content.toString(), true)) : content - }) + if (process.env.UNI_MP_PLUGIN) { + copyOptions.push({ + from: path.resolve(process.env.UNI_INPUT_DIR, 'plugin.json'), + transform: content => JSON.stringify(parseJson(content.toString(), true)) }) + } const workers = platformOptions.workers workers && copyOptions.push(workers) diff --git a/packages/vue-cli-plugin-uni/lib/mp/index.js b/packages/vue-cli-plugin-uni/lib/mp/index.js index 61d16df98..48c1842c0 100644 --- a/packages/vue-cli-plugin-uni/lib/mp/index.js +++ b/packages/vue-cli-plugin-uni/lib/mp/index.js @@ -177,19 +177,11 @@ module.exports = { { const globalEnv = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx' - if (process.env.UNI_MP_PLUGIN) { - // 小程序插件入口使用 - // packages\webpack-uni-mp-loader\lib\plugin\index-new.js -> addMPPluginRequire - addToUniEntry(process.env.UNI_MP_PLUGIN_MAIN) - - beforeCode += `${globalEnv}.__webpack_require_${process.env.UNI_MP_PLUGIN.replace(/-/g, '_')}__ = __webpack_require__;` - } else { - beforeCode += `${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;` - } + ;[].concat(process.env.UNI_MP_PLUGIN ? process.env.UNI_MP_PLUGIN_MAIN : JSON.parse(process.env.UNI_MP_PLUGIN_EXPORT)) + .forEach(fileName => addToUniEntry(fileName)) + beforeCode += `${globalEnv}.__webpack_require_${(process.env.UNI_MP_PLUGIN || 'UNI_MP_PLUGIN').replace(/-/g, '_')}__ = __webpack_require__;` } - JSON.parse(process.env.UNI_MP_PLUGIN_EXPORT).forEach(fileName => addToUniEntry(fileName)) - const alias = { // 仅 mp-weixin 'mpvue-page-factory': require.resolve( '@dcloudio/vue-cli-plugin-uni/packages/mpvue-page-factory') diff --git a/packages/webpack-uni-mp-loader/lib/plugin/index-new.js b/packages/webpack-uni-mp-loader/lib/plugin/index-new.js index 231e201f2..9aa2ef5d5 100644 --- a/packages/webpack-uni-mp-loader/lib/plugin/index-new.js +++ b/packages/webpack-uni-mp-loader/lib/plugin/index-new.js @@ -71,7 +71,8 @@ function addMPPluginRequire (compilation) { const UNI_MP_PLUGIN_MAIN = process.env.UNI_MP_PLUGIN_MAIN const UNI_MP_PLUGIN_EXPORT = JSON.parse(process.env.UNI_MP_PLUGIN_EXPORT) assetsKeys.forEach(name => { - if ((name === UNI_MP_PLUGIN_MAIN && process.env.UNI_MP_PLUGIN) || UNI_MP_PLUGIN_EXPORT.includes(name)) { + const needProcess = process.env.UNI_MP_PLUGIN ? name === UNI_MP_PLUGIN_MAIN : UNI_MP_PLUGIN_EXPORT.includes(name) + if (needProcess) { const modules = compilation.modules const filePath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, name)) -- GitLab