Skip to content

Commit 819ef14

Browse files
authored
Merge branch 'master' into fix-swiper-nocircular
2 parents 37ecb70 + 4da7979 commit 819ef14

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

packages/webpack-plugin/lib/react/processScript.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const normalize = require('../utils/normalize')
22
const optionProcessorPath = normalize.lib('runtime/optionProcessorReact')
3-
const { buildPagesMap, buildComponentsMap, getRequireScript, buildGlobalParams, stringifyRequest } = require('./script-helper')
3+
const { buildPagesMap, buildComponentsMap, getRequireScript, buildGlobalParams, stringifyRequest, buildI18n } = require('./script-helper')
44

55
module.exports = function (script, {
66
loaderContext,
@@ -17,7 +17,7 @@ module.exports = function (script, {
1717
componentGenerics,
1818
genericsInfo
1919
}, callback) {
20-
const { appInfo } = loaderContext.getMpx()
20+
const { appInfo, i18n } = loaderContext.getMpx()
2121

2222
let scriptSrcMode = srcMode
2323
if (script) {
@@ -62,6 +62,9 @@ import { getComponent, getAsyncSuspense } from ${stringifyRequest(loaderContext,
6262
})
6363

6464
output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, ctorType, jsonConfig, componentsMap, outputPath, genericsInfo, componentGenerics, hasApp })
65+
if (!hasApp && i18n) {
66+
output += buildI18n({ loaderContext })
67+
}
6568
output += getRequireScript({ ctorType, script, loaderContext })
6669
output += `export default global.__mpxOptionsMap[${JSON.stringify(moduleId)}]\n`
6770
}

packages/webpack-plugin/lib/web/processMainScript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { processAppOption, getComponent } from ${stringifyRequest(loaderContext,
4949
Vue.use(VueRouter)\n`
5050

5151
if (i18n) {
52-
output += buildI18n({ i18n, loaderContext })
52+
output += buildI18n({ i18n, isMain: true, loaderContext })
5353
}
5454

5555
output += buildGlobalParams({

packages/webpack-plugin/lib/web/processScript.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const {
77
buildComponentsMap,
88
getRequireScript,
99
buildGlobalParams,
10-
stringifyRequest
10+
stringifyRequest,
11+
buildI18n
1112
} = require('./script-helper')
1213

1314
module.exports = function (script, {
@@ -24,7 +25,7 @@ module.exports = function (script, {
2425
wxsModuleMap,
2526
localComponentsMap
2627
}, callback) {
27-
const { projectRoot, appInfo, webConfig } = loaderContext.getMpx()
28+
const { projectRoot, appInfo, webConfig, i18n } = loaderContext.getMpx()
2829

2930
let output = '/* script */\n'
3031

@@ -70,6 +71,9 @@ module.exports = function (script, {
7071
}
7172

7273
content += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, webConfig, hasApp })
74+
if (!hasApp && i18n) {
75+
content += buildI18n({ i18n, loaderContext })
76+
}
7377
content += getRequireScript({ ctorType, script, loaderContext })
7478
content += `
7579
export default processComponentOption({

packages/webpack-plugin/lib/web/script-helper.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,17 @@ function buildGlobalParams ({
186186
return content
187187
}
188188

189-
function buildI18n ({ i18n, loaderContext }) {
189+
function buildI18n ({ i18n, isMain, loaderContext }) {
190190
let i18nContent = ''
191191
const i18nObj = Object.assign({}, i18n)
192-
i18nContent += `
193-
import VueI18n from 'vue-i18n'
192+
if (!isMain) {
193+
i18nContent += `import Vue from 'vue'
194+
import Mpx from '@mpxjs/core'\n`
195+
}
196+
i18nContent += `import VueI18n from 'vue-i18n'
194197
import { createI18n } from 'vue-i18n-bridge'
195-
Vue.use(VueI18n , { bridge: true })\n`
198+
if (!Mpx.i18n) {
199+
Vue.use(VueI18n , { bridge: true })\n`
196200
const requestObj = {}
197201
const i18nKeys = ['messages', 'dateTimeFormats', 'numberFormats']
198202
i18nKeys.forEach((key) => {
@@ -201,15 +205,16 @@ function buildI18n ({ i18n, loaderContext }) {
201205
delete i18nObj[`${key}Path`]
202206
}
203207
})
204-
i18nContent += ` var i18nCfg = ${JSON.stringify(i18nObj)}\n`
208+
i18nContent += ` var i18nCfg = ${JSON.stringify(i18nObj)}\n`
205209
Object.keys(requestObj).forEach((key) => {
206-
i18nContent += ` i18nCfg.${key} = require(${requestObj[key]})\n`
210+
i18nContent += ` i18nCfg.${key} = require(${requestObj[key]})\n`
207211
})
208212
i18nContent += `
209-
i18nCfg.legacy = false
210-
var i18n = createI18n(i18nCfg, VueI18n)
211-
Vue.use(i18n)
212-
Mpx.i18n = i18n\n`
213+
i18nCfg.legacy = false
214+
var i18n = createI18n(i18nCfg, VueI18n)
215+
Vue.use(i18n)
216+
Mpx.i18n = i18n
217+
}\n`
213218
return i18nContent
214219
}
215220

0 commit comments

Comments
 (0)