@mpxjs/webpack-plugin 2.9.43 → 2.9.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,7 @@ module.exports = function getSpec ({ warn, error }) {
19
19
  if (name.startsWith('data-')) {
20
20
  return {
21
21
  name: ':' + name,
22
- value: `JSON.stringify(${parsed.result})`
22
+ value: `__ensureString(${parsed.result})`
23
23
  }
24
24
  } else if (parsed.hasBinding) {
25
25
  return {
@@ -25,7 +25,7 @@ module.exports = function ({
25
25
  callback
26
26
  }) {
27
27
  if (ctorType === 'app' && !queryObj.isApp) {
28
- return processMainScript(parts.script, {
28
+ return processMainScript({
29
29
  loaderContext
30
30
  }, (err, scriptRes) => {
31
31
  if (err) return callback(err)
@@ -1,16 +1,20 @@
1
1
  // 该文件下的字符串语句需要使用 es5 语法
2
2
  const addQuery = require('../utils/add-query')
3
-
4
3
  const {
5
- stringifyRequest
4
+ stringifyRequest,
5
+ buildI18n
6
6
  } = require('./script-helper')
7
7
 
8
- module.exports = function (script, {
8
+ module.exports = function ({
9
9
  loaderContext
10
10
  }, callback) {
11
- const { projectName } = loaderContext.getMpx()
11
+ const { i18n, projectName } = loaderContext.getMpx()
12
12
 
13
13
  let output = 'import { AppRegistry } from \'react-native\'\n'
14
+
15
+ if (i18n) {
16
+ output += buildI18n({ loaderContext })
17
+ }
14
18
  // 此处可添加前置于App执行的语句
15
19
  output += `var App = require(${stringifyRequest(loaderContext, addQuery(loaderContext.resource, { isApp: true }))}).default\n`
16
20
  output += `AppRegistry.registerComponent(${JSON.stringify(projectName)}, () => App)\n`
@@ -77,6 +77,7 @@ module.exports = function (template, {
77
77
  hasScoped: false,
78
78
  moduleId,
79
79
  filePath: resourcePath,
80
+ // react中模版i18n不需要特殊处理
80
81
  i18n: null,
81
82
  checkUsingComponents,
82
83
  // web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
@@ -2,6 +2,7 @@ const loaderUtils = require('loader-utils')
2
2
  const createHelpers = require('../helpers')
3
3
  const parseRequest = require('../utils/parse-request')
4
4
  const shallowStringify = require('../utils/shallow-stringify')
5
+ const normalize = require('../utils/normalize')
5
6
 
6
7
  function stringifyRequest (loaderContext, request) {
7
8
  return loaderUtils.stringifyRequest(loaderContext, request)
@@ -125,10 +126,18 @@ global.currentInject.firstPage = ${JSON.stringify(firstPage)}\n`
125
126
  return content
126
127
  }
127
128
 
129
+ function buildI18n ({ loaderContext }) {
130
+ const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
131
+ const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
132
+ const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
133
+ return `require(${stringifyRequest(loaderContext, i18nWxsRequest)})\n`
134
+ }
135
+
128
136
  module.exports = {
129
137
  buildPagesMap,
130
138
  buildComponentsMap,
131
139
  getRequireScript,
132
140
  buildGlobalParams,
133
- stringifyRequest
141
+ stringifyRequest,
142
+ buildI18n
134
143
  }
package/lib/web/index.js CHANGED
@@ -35,13 +35,9 @@ module.exports = function ({
35
35
  }, callback)
36
36
  },
37
37
  (jsonRes, callback) => {
38
- processMainScript(parts.script, {
38
+ processMainScript({
39
39
  loaderContext,
40
- srcMode,
41
- moduleId,
42
- isProduction,
43
40
  jsonConfig: jsonRes.jsonObj,
44
- outputPath: queryObj.outputPath || '',
45
41
  localComponentsMap: jsonRes.localComponentsMap,
46
42
  tabBar: jsonRes.jsonObj.tabBar,
47
43
  tabBarMap: jsonRes.tabBarMap,
@@ -12,11 +12,8 @@ const {
12
12
  buildI18n
13
13
  } = require('./script-helper')
14
14
 
15
- module.exports = function (script, {
15
+ module.exports = function ({
16
16
  loaderContext,
17
- srcMode,
18
- moduleId,
19
- isProduction,
20
17
  jsonConfig,
21
18
  localComponentsMap,
22
19
  tabBar,
@@ -40,8 +37,6 @@ module.exports = function (script, {
40
37
  jsonConfig
41
38
  })
42
39
 
43
- const scriptSrcMode = script ? script.mode || srcMode : srcMode
44
-
45
40
  let output = 'import \'@mpxjs/webpack-plugin/lib/runtime/base.styl\'\n'
46
41
  // hasUnoCSS由@mpxjs/unocss-plugin注入
47
42
  if (hasUnoCSS) {
@@ -58,10 +53,7 @@ Vue.use(VueRouter)\n`
58
53
  }
59
54
 
60
55
  output += buildGlobalParams({
61
- moduleId,
62
- scriptSrcMode,
63
56
  loaderContext,
64
- isProduction,
65
57
  jsonConfig,
66
58
  webConfig,
67
59
  isMain: true,
@@ -170,17 +170,18 @@ function buildGlobalParams ({
170
170
  if (globalTabBar) {
171
171
  content += globalTabBar
172
172
  }
173
- } else if (!hasApp) {
174
- content += `
175
- global.__mpxGenericsMap = global.__mpxGenericsMap || {}
176
- global.__mpxOptionsMap = global.__mpxOptionsMap || {}
177
- global.__mpxTransRpxFn = ${webConfig.transRpxFn} \n`
178
- }
179
- content += ` global.currentModuleId = ${JSON.stringify(moduleId)}\n`
180
- content += ` global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
181
- content += ` global.currentInject = ${JSON.stringify({ moduleId })}\n`
182
- if (!isProduction) {
183
- content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
173
+ } else {
174
+ if (!hasApp) {
175
+ content += ' global.__mpxGenericsMap = global.__mpxGenericsMap || {}\n'
176
+ content += ' global.__mpxOptionsMap = global.__mpxOptionsMap || {}\n'
177
+ content += ` global.__mpxTransRpxFn = ${webConfig.transRpxFn}\n`
178
+ }
179
+ content += ` global.currentModuleId = ${JSON.stringify(moduleId)}\n`
180
+ content += ` global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
181
+ content += ` global.currentInject = ${JSON.stringify({ moduleId })}\n`
182
+ if (!isProduction) {
183
+ content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
184
+ }
184
185
  }
185
186
  return content
186
187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.43",
3
+ "version": "2.9.50",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -85,5 +85,5 @@
85
85
  "engines": {
86
86
  "node": ">=14.14.0"
87
87
  },
88
- "gitHead": "92a347518d15400f87c380bc7248b8b6254631cf"
88
+ "gitHead": "d8b89e0ba1f29a16244b247f6c7a8d8197e0d732"
89
89
  }