@mpxjs/webpack-plugin 2.8.41 → 2.8.42

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.
@@ -177,14 +177,14 @@ module.exports = function (content) {
177
177
  type: 'json',
178
178
  waterfall: true,
179
179
  warn: emitWarning,
180
- error: emitError
180
+ error: emitError,
181
+ data: {
182
+ // polyfill global usingComponents & record globalComponents
183
+ globalComponents: mpx.usingComponents
184
+ }
181
185
  }
182
186
  if (!isApp) {
183
187
  rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
184
- // polyfill global usingComponents
185
- rulesRunnerOptions.data = {
186
- globalComponents: mpx.usingComponents
187
- }
188
188
  }
189
189
 
190
190
  const rulesRunner = getRulesRunner(rulesRunnerOptions)
@@ -193,9 +193,12 @@ module.exports = function (content) {
193
193
  rulesRunner(json)
194
194
  }
195
195
 
196
- if (isApp && json.usingComponents) {
196
+ if (isApp) {
197
+ Object.assign(mpx.usingComponents, json.usingComponents)
197
198
  // 在 rulesRunner 运行后保存全局注册组件
198
- this._module.addPresentationalDependency(new RecordGlobalComponentsDependency(json.usingComponents, this.context))
199
+ // todo 其余地方在使用mpx.usingComponents时存在缓存问题,要规避该问题需要在所有使用mpx.usingComponents的loader中添加app resourcePath作为fileDependency,但对于缓存有效率影响巨大
200
+ // todo 需要考虑一种精准控制缓存的方式,仅在全局组件发生变更时才使相关使用方的缓存失效,例如按需在相关模块上动态添加request query?
201
+ this._module.addPresentationalDependency(new RecordGlobalComponentsDependency(mpx.usingComponents, this.context))
199
202
  }
200
203
 
201
204
  const processComponents = (components, context, callback) => {
package/lib/loader.js CHANGED
@@ -120,7 +120,6 @@ module.exports = function (content) {
120
120
 
121
121
  let usingComponents = [].concat(Object.keys(mpx.usingComponents))
122
122
  let componentPlaceholder = []
123
-
124
123
  let componentGenerics = {}
125
124
 
126
125
  if (parts.json && parts.json.content) {
@@ -134,18 +133,12 @@ module.exports = function (content) {
134
133
  }
135
134
  if (!isApp) {
136
135
  rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
137
- // polyfill global usingComponents
138
- // 预读json时无需注入polyfill全局组件
139
- // rulesRunnerOptions.data = {
140
- // globalComponents: mpx.usingComponents
141
- // }
142
136
  }
143
-
137
+ const rulesRunner = getRulesRunner(rulesRunnerOptions)
144
138
  try {
145
139
  const ret = JSON5.parse(parts.json.content)
140
+ if (rulesRunner) rulesRunner(ret)
146
141
  if (ret.usingComponents) {
147
- const rulesRunner = getRulesRunner(rulesRunnerOptions)
148
- if (rulesRunner) rulesRunner(ret)
149
142
  usingComponents = usingComponents.concat(Object.keys(ret.usingComponents))
150
143
  }
151
144
  if (ret.componentPlaceholder) {
@@ -137,6 +137,7 @@ module.exports = function (content) {
137
137
  } catch (e) {
138
138
  return callback(e)
139
139
  }
140
+ let usingComponents = Object.keys(mpx.usingComponents)
140
141
  const rulesRunnerOptions = {
141
142
  mode,
142
143
  srcMode,
@@ -147,16 +148,10 @@ module.exports = function (content) {
147
148
  }
148
149
  if (!isApp) {
149
150
  rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
150
- // polyfill global usingComponents
151
- // 预读json时无需注入polyfill全局组件
152
- // rulesRunnerOptions.data = {
153
- // globalComponents: mpx.usingComponents
154
- // }
155
151
  }
156
- let usingComponents = Object.keys(mpx.usingComponents)
152
+ const rulesRunner = getRulesRunner(rulesRunnerOptions)
153
+ if (rulesRunner) rulesRunner(json)
157
154
  if (json.usingComponents) {
158
- const rulesRunner = getRulesRunner(rulesRunnerOptions)
159
- if (rulesRunner) rulesRunner(json)
160
155
  usingComponents = usingComponents.concat(Object.keys(json.usingComponents))
161
156
  }
162
157
  const {
@@ -70,6 +70,13 @@ module.exports = function getSpec ({ warn, error }) {
70
70
  return input
71
71
  }
72
72
 
73
+ function fillGlobalComponents (input, { globalComponents }) {
74
+ if (globalComponents) {
75
+ Object.assign(globalComponents, input.usingComponents)
76
+ }
77
+ return input
78
+ }
79
+
73
80
  // 处理 ali swan 的组件名大写字母转连字符:WordExample/wordExample -> word-example
74
81
  function componentNameCapitalToHyphen (type) {
75
82
  return function (input) {
@@ -318,6 +325,20 @@ module.exports = function getSpec ({ warn, error }) {
318
325
  tt: deletePath(),
319
326
  jd: deletePath(true)
320
327
  },
328
+ {
329
+ test: 'usingComponents',
330
+ ali: componentNameCapitalToHyphen('usingComponents'),
331
+ swan: componentNameCapitalToHyphen('usingComponents')
332
+ },
333
+ {
334
+ test: 'usingComponents',
335
+ // todo ali 2.0已支持全局组件,待移除
336
+ ali: fillGlobalComponents,
337
+ qq: fillGlobalComponents,
338
+ swan: fillGlobalComponents,
339
+ tt: fillGlobalComponents,
340
+ jd: fillGlobalComponents
341
+ },
321
342
  {
322
343
  test: 'usingComponents',
323
344
  // todo ali 2.0已支持全局组件,待移除
@@ -1,14 +1,10 @@
1
1
  const { capitalToHyphen } = require('../../../../utils/string')
2
2
 
3
3
  module.exports = function () {
4
- function convertTagName (name) {
5
- return capitalToHyphen(name)
6
- }
7
-
8
4
  return {
9
5
  // tag name contains capital letters
10
6
  test: /[A-Z]/,
11
- ali: convertTagName,
12
- swan: convertTagName
7
+ ali: capitalToHyphen,
8
+ swan: capitalToHyphen
13
9
  }
14
10
  }
@@ -8,7 +8,7 @@ const checkbox = require('./checkbox')
8
8
  const coverImage = require('./cover-image')
9
9
  const coverView = require('./cover-view')
10
10
  const form = require('./form')
11
- const HyphenTagName = require('./hypen-tag-name')
11
+ const hyphenTagName = require('./hypen-tag-name')
12
12
  const icon = require('./icon')
13
13
  const image = require('./image')
14
14
  const input = require('./input')
@@ -118,7 +118,7 @@ module.exports = function getComponentConfigs ({ warn, error }) {
118
118
  camera({ print }),
119
119
  livePlayer({ print }),
120
120
  livePusher({ print }),
121
- HyphenTagName({ print }),
121
+ hyphenTagName({ print }),
122
122
  component()
123
123
  ]
124
124
  }
@@ -190,16 +190,16 @@ module.exports = function getSpec ({ warn, error }) {
190
190
  }
191
191
  const styleBinding = []
192
192
  el.isStyleParsed = true
193
- el.attrsList.forEach((item) => {
193
+ // 不过滤的话每一个属性都要 parse
194
+ el.attrsList.filter(item => this.test.test(item.name)).forEach((item) => {
194
195
  const parsed = parseMustache(item.value)
195
- if (item.name === 'style') {
196
- if (parsed.hasBinding || parsed.result.indexOf('rpx') > -1) {
197
- styleBinding.push(parseMustache(item.value).result)
198
- } else {
199
- styleBinding.push(JSON.stringify(item.value))
200
- }
201
- } else if (item.name === 'wx:style') {
202
- styleBinding.push(parseMustache(item.value).result)
196
+ if (item.name === 'wx:style') {
197
+ styleBinding.push(parsed.result)
198
+ // item.name === 'style'
199
+ } else if (parsed.hasBinding || parsed.result.indexOf('rpx') > -1) {
200
+ styleBinding.push(parsed.result)
201
+ } else {
202
+ styleBinding.push(JSON.stringify(item.value))
203
203
  }
204
204
  })
205
205
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.41",
3
+ "version": "2.8.42",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -82,5 +82,5 @@
82
82
  "engines": {
83
83
  "node": ">=14.14.0"
84
84
  },
85
- "gitHead": "f3bfd9bf76756bebe92204e4b87b182b1b5b5502"
85
+ "gitHead": "a0d7f0171b8e4535f1962bdb7415fec0d25abe93"
86
86
  }