diff --git a/packages/uni-mp-alipay/lib/uni.config.js b/packages/uni-mp-alipay/lib/uni.config.js index b1b78060fac74c7b6e6cd095afb91adabd588dce..3d03fb09dbd66b8cab35e36697a3e962e5b5528c 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 c6ef0d0a82b887dfc5f2be5628b9092f2cefba55..8ffbc50ce51e49841bc8297fa13f32717585d387 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 61d16df988fdc5f87981ef761c19f045479c5893..48c1842c0501a066966690aad8cc5e083f6b12dd 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 231e201f20423e4641d3055d3bf7a02d4c838df6..9aa2ef5d57f87c119c763383caddf5b99cdd9327 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))