From a5e95f2c20e87ba4f9575cfe35523024bd73ab12 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 6 Sep 2022 15:27:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=20androidPrivacy.json?= =?UTF-8?q?=20=E6=96=87=E4=BB=B6=E6=8B=B7=E8=B4=9D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../build/webpack.nvue.conf.js | 28 ++++++++++++++--- .../lib/copy-webpack-options.js | 31 +++++-------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js index 4f572e503..97be217ee 100644 --- a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js +++ b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js @@ -13,6 +13,12 @@ const { getTemplatePath } = require('@dcloudio/uni-cli-shared') const fileLoader = require('@dcloudio/uni-cli-shared/lib/file-loader') +const { + compileI18nJsonStr +} = require('@dcloudio/uni-i18n') +const { + initI18nOptions +} = require('@dcloudio/uni-cli-shared/lib/i18n') const WebpackAppPlusNVuePlugin = process.env.UNI_USING_V3 ? require('../packages/webpack-app-plus-plugin') : require('../packages/webpack-app-plus-nvue-plugin') @@ -226,11 +232,25 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { }] // 自动化测试时,不启用androidPrivacy.json if (!process.env.UNI_AUTOMATOR_WS_ENDPOINT) { - const androidPrivacyPath = path.resolve(process.env.UNI_INPUT_DIR, 'androidPrivacy.json') - if (fs.existsSync(androidPrivacyPath)) { + const fileName = 'androidPrivacy.json' + const context = path.resolve(process.env.UNI_INPUT_DIR) + if (fs.existsSync(path.join(context, fileName))) { patterns.push({ - from: androidPrivacyPath, - to: 'androidPrivacy.json' + from: fileName, + context, + to: fileName, + transform (content) { + const options = initI18nOptions( + process.env.UNI_PLATFORM, + process.env.UNI_INPUT_DIR, + false, + true + ) + if (!options) { + return content + } + return compileI18nJsonStr(content.toString(), options) + } }) } } diff --git a/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js b/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js index 76d7e9e5e..4fe5c91df 100644 --- a/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js +++ b/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js @@ -92,16 +92,14 @@ function getCopyWebpackPluginOptions (platformOptions, vueOptions) { }) // 自动化测试时,不启用androidPrivacy.json if (process.env.UNI_PLATFORM === 'app-plus' && !process.env.UNI_AUTOMATOR_WS_ENDPOINT) { - const from = 'android*.json' const fileName = 'androidPrivacy.json' const context = path.resolve(process.env.UNI_INPUT_DIR) - const options = { - from, - context, - to: `[name]${CopyWebpackPluginVersion > 5 ? '' : '.'}[ext]`, - noErrorOnMissing: true, - transform (content, path) { - if (path.endsWith(fileName)) { + if (fs.existsSync(path.join(context, fileName))) { + copyOptions.push({ + from: fileName, + context, + to: fileName, + transform (content) { const options = initI18nOptions( process.env.UNI_PLATFORM, process.env.UNI_INPUT_DIR, @@ -113,22 +111,7 @@ function getCopyWebpackPluginOptions (platformOptions, vueOptions) { } return compileI18nJsonStr(content.toString(), options) } - return content - } - } - // copy-webpack-plugin/glob-parent 存在 Bug,例如:/test/dir(1 - const globParent = require(require.resolve('glob-parent', { paths: [require.resolve('copy-webpack-plugin')] })) - const parent = globParent(path.join(context, from)) - let canNotWatch - if (parent !== context) { - options.from = fileName - if (!fs.existsSync(path.join(context, fileName))) { - canNotWatch = true - // console.warn(`invalid path: ${context}, can not watch ${fileName}`) - } - } - if (!canNotWatch) { - copyOptions.push(options) + }) } } return copyOptions -- GitLab