diff --git a/packages/uni-cli-i18n/locales/en.json b/packages/uni-cli-i18n/locales/en.json index 732a527e238fd5967e03438882aaefe3cb5441ab..b8fe269955faebeafcdd25798c469d9832ba7c91 100644 --- a/packages/uni-cli-i18n/locales/en.json +++ b/packages/uni-cli-i18n/locales/en.json @@ -42,7 +42,7 @@ "pluginUni.runDebugMode": "Please note that in running mode, due to log output, sourcemap, and uncompressed source code, the performance and package size are not as good as release mode.", "pluginUni.runDebugModeNvue": "Especially the sourcemap of app-nvue has a greater impact", "pluginUni.runDebugModeMP": "To officially release, please click the release menu or use the cli release command to release", - "pluginUni.compileToMpPluginOnlySupportWeChat": "Compile to mini-program plug-in only supports WeChat mini-program", + "pluginUni.compileToMpPluginOnlySupportPlatform": "Compile to mini-program plug-in only supports WeChat mini-program and AliPay mini-program", "pluginUni.startCompileProjectToPlatform": "Start to compile the current project to the {{0}} {{1}}...", "pluginUni.fileNoExistsCheckAfterRetry": "{{0}} file does not exist, please check and try again", "pluginUni.entryDileNoExistsCheckAfterRetry": "{{0}} The entry file does not exist, please check and try again", @@ -67,4 +67,4 @@ "pagesLoader.needInPagesNode": "{{0}} needs to be in the pages array", "i18n.fallbackLocale.default": "fallbackLocale is missing in manifest.json, use:{{locale}}", "i18n.fallbackLocale.missing": "./local/{locale}.json is missing" -} +} diff --git a/packages/uni-cli-i18n/locales/zh_CN.json b/packages/uni-cli-i18n/locales/zh_CN.json index 0469768740172c243b1678a8994d092324c50fb5..bb86f7a7e17e9bec2d0b1ef226e280e670898bd2 100644 --- a/packages/uni-cli-i18n/locales/zh_CN.json +++ b/packages/uni-cli-i18n/locales/zh_CN.json @@ -42,7 +42,7 @@ "pluginUni.runDebugMode": "请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。", "pluginUni.runDebugModeNvue": "尤其是app-nvue的sourcemap影响较大", "pluginUni.runDebugModeMP": "若要正式发布,请点击发行菜单或使用cli发布命令进行发布", - "pluginUni.compileToMpPluginOnlySupportWeChat": "编译到小程序插件只支持微信小程序", + "pluginUni.compileToMpPluginOnlySupportPlatform": "编译到小程序插件只支持微信小程序和阿里小程序", "pluginUni.startCompileProjectToPlatform": "开始编译当前项目至 {{0}} {{1}}...", "pluginUni.fileNoExistsCheckAfterRetry": "{{0}} 文件不存在,请检查后重试", "pluginUni.entryDileNoExistsCheckAfterRetry": "{{0}} 入口文件不存在,请检查后重试", @@ -67,4 +67,4 @@ "pagesLoader.needInPagesNode": "{{0}} 需在 pages 数组中", "i18n.fallbackLocale.default": "当前应用未在 manifest.json 配置 fallbackLocale,默认使用:{{locale}}", "i18n.fallbackLocale.missing": "当前应用配置的 fallbackLocale 或 locale 为:{locale},但 locale 目录缺少该语言文件" -} +} diff --git a/packages/uni-mp-alipay/lib/uni.config.js b/packages/uni-mp-alipay/lib/uni.config.js index 4baf785d6f572709b3eeb467261fc0c3c5bf74ce..3d03fb09dbd66b8cab35e36697a3e962e5b5528c 100644 --- a/packages/uni-mp-alipay/lib/uni.config.js +++ b/packages/uni-mp-alipay/lib/uni.config.js @@ -1,3 +1,6 @@ +const path = require('path') +const { parseJson } = require('@dcloudio/uni-cli-shared/lib/json') + module.exports = { options: { global: 'my', @@ -21,6 +24,14 @@ module.exports = { global.uniModules.forEach(module => { copyOptions.push('uni_modules/' + module + '/mycomponents') }) + + 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 fbe51732153e5649cf47128344f64359d4d3a20b..8ffbc50ce51e49841bc8297fa13f32717585d387 100644 --- a/packages/uni-mp-weixin/lib/uni.config.js +++ b/packages/uni-mp-weixin/lib/uni.config.js @@ -1,5 +1,6 @@ const fs = require('fs') const path = require('path') +const { parseJson } = require('@dcloudio/uni-cli-shared/lib/json') const COMPONENTS_DIR_NAME = 'wxcomponents' @@ -31,7 +32,12 @@ module.exports = { 'functional-pages' ] - if (process.env.UNI_MP_PLUGIN) copyOptions.push('plugin.json') + 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/commands/build.js b/packages/vue-cli-plugin-uni/commands/build.js index e3cdd53aa86f0e8f58ff6470e7827201492ad4f3..00f5a8702542e2bd5607618327566ceba2e4a6ce 100644 --- a/packages/vue-cli-plugin-uni/commands/build.js +++ b/packages/vue-cli-plugin-uni/commands/build.js @@ -2,7 +2,8 @@ const path = require('path') const { runByHBuilderX, - isInHBuilderX + isInHBuilderX, + parseJson } = require('@dcloudio/uni-cli-shared') const uniI18n = require('@dcloudio/uni-cli-i18n') @@ -45,13 +46,14 @@ module.exports = (api, options) => { process.env.UNI_SUBPACKGE = args.subpackage } + const mpPluginPlatforms = ['mp-weixin', 'mp-alipay'] if (args.plugin) { - if (process.env.UNI_PLATFORM === 'mp-weixin') { + if (mpPluginPlatforms.includes(process.env.UNI_PLATFORM)) { process.env.UNI_MP_PLUGIN = args.plugin analysisPluginDir() } else { console.log() - console.error(uniI18n.__('pluginUni.compileToMpPluginOnlySupportWeChat')) + console.error(uniI18n.__('pluginUni.compileToMpPluginOnlySupportPlatform')) console.log() process.exit(0) } @@ -224,7 +226,7 @@ function analysisPluginDir () { process.exit(0) } - const pluginJson = require(pluginJsonPath) + const pluginJson = parseJson(fs.readFileSync(pluginJsonPath, 'utf-8'), true) // main 入口文件是否存在 process.env.UNI_MP_PLUGIN_MAIN = pluginJson.main diff --git a/packages/vue-cli-plugin-uni/lib/mp/index.js b/packages/vue-cli-plugin-uni/lib/mp/index.js index 1a8e09aaf0e68a858dcbaed9f11aab1f84a226ff..99d4af1cea7abec009538dd542b5961b63dbe79e 100644 --- a/packages/vue-cli-plugin-uni/lib/mp/index.js +++ b/packages/vue-cli-plugin-uni/lib/mp/index.js @@ -84,11 +84,13 @@ function processWxss (name, assets) { } } +const parseRequirePath = path => path.startsWith('common') ? `./${path}` : path + function procssJs (name, assets, hasVendor) { const dirname = path.dirname(name) - const runtimeJsCode = `require('${normalizePath(path.relative(dirname, 'common/runtime.js'))}');` - const vendorJsCode = hasVendor ? `require('${normalizePath(path.relative(dirname, 'common/vendor.js'))}');` : '' - const mainJsCode = `require('${normalizePath(path.relative(dirname, 'common/main.js'))}');` + const runtimeJsCode = `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/runtime.js')))}');` + const vendorJsCode = hasVendor ? `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/vendor.js')))}');` : '' + const mainJsCode = `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/main.js')))}');` const code = `${runtimeJsCode}${vendorJsCode}${mainJsCode}` + assets[name].source().toString() assets[name] = { size () { @@ -172,7 +174,7 @@ module.exports = { if (process.env.UNI_MP_PLUGIN) { // 小程序插件入口使用 // packages\webpack-uni-mp-loader\lib\plugin\index-new.js -> addMPPluginRequire - beforeCode += `wx.__webpack_require_${process.env.UNI_MP_PLUGIN.replace(/-/g, '_')}__ = __webpack_require__;` + beforeCode += `${process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx'}.__webpack_require_${process.env.UNI_MP_PLUGIN.replace(/-/g, '_')}__ = __webpack_require__;` const UNI_MP_PLUGIN_MAIN = process.env.UNI_MP_PLUGIN_MAIN if (UNI_MP_PLUGIN_MAIN) { @@ -309,4 +311,4 @@ module.exports = { webpackConfig.plugins.delete('preload') webpackConfig.plugins.delete('prefetch') } -} +} 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 40786c21bb3854d9bd78e18a16b2f5348aa9d6bb..8c3fa3e87114af66d55f4cb8f93a35b2943e7e32 100644 --- a/packages/webpack-uni-mp-loader/lib/plugin/index-new.js +++ b/packages/webpack-uni-mp-loader/lib/plugin/index-new.js @@ -80,7 +80,7 @@ function addMPPluginRequire (compilation) { const newlineIndex = compilation.assets[name].source().lastIndexOf('\n') const source = compilation.assets[name].source().substring(0, newlineIndex) + - `\nmodule.exports = wx.__webpack_require_${process.env.UNI_MP_PLUGIN.replace(/-/g, '_')}__('${uniModuleId}');\n` + + `\nmodule.exports = ${process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx'}.__webpack_require_${process.env.UNI_MP_PLUGIN.replace(/-/g, '_')}__('${uniModuleId}');\n` + compilation.assets[name].source().substring(newlineIndex + 1) compilation.assets[name] = {