提交 cc8fa0e6 编写于 作者: fxy060608's avatar fxy060608

fix(mp): pages.json with i18n

上级 4ed11e3d
......@@ -18,6 +18,7 @@
"license": "Apache-2.0",
"dependencies": {
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3040520220408002",
"@dcloudio/uni-i18n": "3.0.0-alpha-3040520220408002",
"@dcloudio/uni-mp-compiler": "3.0.0-alpha-3040520220408002",
"@dcloudio/uni-mp-vue": "3.0.0-alpha-3040520220408002",
"@dcloudio/uni-shared": "3.0.0-alpha-3040520220408002",
......
......@@ -14,9 +14,11 @@ import {
findChangedJsonFiles,
mergeMiniProgramAppJson,
MANIFEST_JSON_JS,
initI18nOptionsOnce,
} from '@dcloudio/uni-cli-shared'
import { virtualPagePath } from './entry'
import { UniMiniProgramPluginOptions } from '../plugin'
import { parseI18nJson } from '@dcloudio/uni-i18n'
const debugPagesJson = debug('uni:pages-json')
......@@ -29,6 +31,8 @@ export function uniPagesJsonPlugin(
options: UniMiniProgramPluginOptions
): Plugin {
let resolvedConfig: ResolvedConfig
const platform = process.env.UNI_PLATFORM
const inputDir = process.env.UNI_INPUT_DIR
return defineUniPagesJsonPlugin((opts) => {
return {
name: 'uni:mp-pages-json',
......@@ -40,7 +44,6 @@ export function uniPagesJsonPlugin(
if (!opts.filter(id)) {
return null
}
const inputDir = process.env.UNI_INPUT_DIR
this.addWatchFile(path.resolve(inputDir, 'pages.json'))
getLocaleFiles(path.resolve(inputDir, 'locale')).forEach((filepath) => {
this.addWatchFile(filepath)
......@@ -48,7 +51,7 @@ export function uniPagesJsonPlugin(
const manifestJson = parseManifestJsonOnce(inputDir)
const { appJson, pageJsons, nvuePages } = parseMiniProgramPagesJson(
code,
process.env.UNI_PLATFORM,
platform,
{
debug: !!manifestJson.debug,
darkmode:
......@@ -64,11 +67,19 @@ export function uniPagesJsonPlugin(
nvuePages.map((pagePath) => pagePath + options.style.extname)
)
mergeMiniProgramAppJson(appJson, manifestJson[process.env.UNI_PLATFORM])
mergeMiniProgramAppJson(appJson, manifestJson[platform])
if (options.json?.formatAppJson) {
options.json.formatAppJson(appJson, manifestJson, pageJsons)
}
// 使用 once 获取的话,可以节省编译时间,但 i18n 内容发生变化时,pages.json 不会自动更新
const i18nOptions = initI18nOptionsOnce(platform, inputDir, false, true)
if (i18nOptions) {
const { locale, locales, delimiters } = i18nOptions
parseI18nJson(appJson, locales[locale], delimiters)
parseI18nJson(pageJsons, locales[locale], delimiters)
}
const { normalize } = options.app
addMiniProgramAppJson(normalize ? normalize(appJson) : appJson)
Object.keys(pageJsons).forEach((name) => {
......
......@@ -609,6 +609,7 @@ importers:
packages/uni-mp-vite:
specifiers:
'@dcloudio/uni-cli-shared': 3.0.0-alpha-3040520220408002
'@dcloudio/uni-i18n': 3.0.0-alpha-3040520220408002
'@dcloudio/uni-mp-compiler': 3.0.0-alpha-3040520220408002
'@dcloudio/uni-mp-vue': 3.0.0-alpha-3040520220408002
'@dcloudio/uni-shared': 3.0.0-alpha-3040520220408002
......@@ -619,6 +620,7 @@ importers:
magic-string: ^0.26.1
dependencies:
'@dcloudio/uni-cli-shared': link:../uni-cli-shared
'@dcloudio/uni-i18n': link:../uni-i18n
'@dcloudio/uni-mp-compiler': link:../uni-mp-compiler
'@dcloudio/uni-mp-vue': link:../uni-mp-vue
'@dcloudio/uni-shared': link:../uni-shared
......@@ -5557,7 +5559,7 @@ packages:
resolution: {integrity: sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==}
/graceful-fs/4.2.9:
resolution: {integrity: sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==, registry: https://registry.yarnpkg.com/}
resolution: {integrity: sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==, registry: https://registry.yarnpkg.com/, tarball: https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz}
requiresBuild: true
/has-flag/3.0.0:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册