@mpxjs/webpack-plugin 2.9.0 → 2.9.3

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.
@@ -1,15 +1,26 @@
1
1
  const runRules = require('./run-rules')
2
-
3
- module.exports = function getRulesRunner ({ type, mode, srcMode, data, meta, testKey, mainKey, waterfall, warn, error }) {
4
- const specMap = {
5
- template: {
6
- wx: require('./template/wx')({ warn, error })
7
- },
8
- json: {
9
- wx: require('./json/wx')({ warn, error })
10
- }
2
+ const specMap = {
3
+ template: {
4
+ wx: require('./template/wx')
5
+ },
6
+ json: {
7
+ wx: require('./json/wx')
11
8
  }
12
- const spec = specMap[type] && specMap[type][srcMode]
9
+ }
10
+
11
+ module.exports = function getRulesRunner ({
12
+ type,
13
+ mode,
14
+ srcMode,
15
+ data,
16
+ meta,
17
+ testKey,
18
+ mainKey,
19
+ waterfall,
20
+ warn,
21
+ error
22
+ }) {
23
+ const spec = specMap[type] && specMap[type][srcMode] && specMap[type][srcMode]({ warn, error })
13
24
  if (spec && spec.supportedModes.indexOf(mode) > -1) {
14
25
  const normalizeTest = spec.normalizeTest
15
26
  const mainRules = mainKey ? spec[mainKey] : spec
@@ -128,10 +128,8 @@ module.exports = function getSpec ({ warn, error }) {
128
128
 
129
129
  /**
130
130
  * 将小程序代码中使用的与原生 HTML tag 或 内建组件 同名的组件进行转化,以解决与原生tag命名冲突问题。
131
- * @param {string} type usingComponents
132
- * @returns input
133
131
  */
134
- function webHTMLTagProcesser (type) {
132
+ function fixComponentName (type) {
135
133
  return function (input) {
136
134
  const usingComponents = input[type]
137
135
  if (usingComponents) {
@@ -160,7 +158,7 @@ module.exports = function getSpec ({ warn, error }) {
160
158
  },
161
159
  {
162
160
  test: 'usingComponents',
163
- web: webHTMLTagProcesser('usingComponents')
161
+ web: fixComponentName('usingComponents')
164
162
  },
165
163
  {
166
164
  test: 'usingComponents',
@@ -365,7 +363,7 @@ module.exports = function getSpec ({ warn, error }) {
365
363
  },
366
364
  {
367
365
  test: 'usingComponents',
368
- web: webHTMLTagProcesser('usingComponents')
366
+ web: fixComponentName('usingComponents')
369
367
  },
370
368
  {
371
369
  test: 'usingComponents',
@@ -32,8 +32,7 @@ module.exports = function runRules (rules = [], input, options = {}) {
32
32
  if (result !== undefined) {
33
33
  input = result
34
34
  }
35
- // rule 内外 waterfall 均为 false 时跳过
36
- if (!rule.waterfall && !waterfall) break
35
+ if (!(rule.waterfall || waterfall)) break
37
36
  }
38
37
  }
39
38
  return input
@@ -8,58 +8,57 @@ const runRules = require('../run-rules')
8
8
  module.exports = function normalizeComponentRules (cfgs, spec) {
9
9
  return cfgs.map((cfg) => {
10
10
  const result = {}
11
- if (cfg.test) {
12
- result.test = cfg.test
13
- }
14
- // 透传 waterfall 信息
11
+ if (cfg.test) result.test = cfg.test
15
12
  if (cfg.waterfall) result.waterfall = cfg.waterfall
16
13
  const supportedModes = cfg.supportedModes || spec.supportedModes
17
14
  // 合并component-config中组件的event 与index中公共的event规则
18
15
  const eventRules = (cfg.event || []).concat(spec.event.rules)
19
16
  supportedModes.forEach((mode) => {
20
- result[mode] = function (el, data) {
21
- data = Object.assign({}, data, { el, eventRules })
22
- const testKey = 'name'
23
- let rAttrsList = []
24
- const options = {
25
- mode,
26
- testKey,
27
- data
28
- }
29
- el.attrsList.forEach((attr) => {
30
- const meta = {}
31
- let rAttr = runRules(spec.directive, attr, {
32
- ...options,
33
- meta
34
- })
35
- // 指令未匹配到时说明为props,因为目前所有的指令都需要转换
36
- if (!meta.processed) {
37
- rAttr = runRules(spec.preProps, rAttr, options)
38
- rAttr = runRules(cfg.props, rAttr, options)
17
+ result[mode] = cfg.skipNormalize
18
+ ? cfg[mode]
19
+ : function (el, data) {
20
+ data = Object.assign({}, data, { el, eventRules })
21
+ const testKey = 'name'
22
+ let rAttrsList = []
23
+ const options = {
24
+ mode,
25
+ testKey,
26
+ data
27
+ }
28
+ el.attrsList.forEach((attr) => {
29
+ const meta = {}
30
+ let rAttr = runRules(spec.directive, attr, {
31
+ ...options,
32
+ meta
33
+ })
34
+ // 指令未匹配到时说明为props,因为目前所有的指令都需要转换
35
+ if (!meta.processed) {
36
+ rAttr = runRules(spec.preProps, rAttr, options)
37
+ rAttr = runRules(cfg.props, rAttr, options)
38
+ if (Array.isArray(rAttr)) {
39
+ rAttr = rAttr.map((attr) => {
40
+ return runRules(spec.postProps, attr, options)
41
+ })
42
+ } else if (rAttr !== false) {
43
+ rAttr = runRules(spec.postProps, rAttr, options)
44
+ }
45
+ }
46
+ // 生成目标attrsList
39
47
  if (Array.isArray(rAttr)) {
40
- rAttr = rAttr.map((attr) => {
41
- return runRules(spec.postProps, attr, options)
42
- })
48
+ rAttrsList = rAttrsList.concat(rAttr)
43
49
  } else if (rAttr !== false) {
44
- rAttr = runRules(spec.postProps, rAttr, options)
50
+ rAttrsList.push(rAttr)
45
51
  }
52
+ })
53
+ el.attrsList = rAttrsList
54
+ el.attrsMap = require('../../template-compiler/compiler').makeAttrsMap(rAttrsList)
55
+ // 前置处理attrs,便于携带信息用于tag的处理
56
+ const rTag = cfg[mode] && cfg[mode].call(this, el.tag, data)
57
+ if (rTag) {
58
+ el.tag = rTag
46
59
  }
47
- // 生成目标attrsList
48
- if (Array.isArray(rAttr)) {
49
- rAttrsList = rAttrsList.concat(rAttr)
50
- } else if (rAttr !== false) {
51
- rAttrsList.push(rAttr)
52
- }
53
- })
54
- el.attrsList = rAttrsList
55
- el.attrsMap = require('../../template-compiler/compiler').makeAttrsMap(rAttrsList)
56
- // 前置处理attrs,便于携带信息用于tag的处理
57
- const rTag = cfg[mode] && cfg[mode].call(this, el.tag, data)
58
- if (rTag) {
59
- el.tag = rTag
60
+ return el
60
61
  }
61
- return el
62
- }
63
62
  })
64
63
  return result
65
64
  })
@@ -0,0 +1,21 @@
1
+ const { isOriginTag, isBuildInTag } = require('../../../../utils/dom-tag-config')
2
+
3
+ module.exports = function () {
4
+ return {
5
+ waterfall: true,
6
+ skipNormalize: true,
7
+ supportedModes: ['web'],
8
+ test: (input) => isOriginTag(input) || isBuildInTag(input),
9
+ // 输出web时对组件名进行转义避免与原生tag和内建tag冲突
10
+ web (el, data) {
11
+ const newTag = `mpx-com-${el.tag}`
12
+ const usingComponents = data.usingComponents || []
13
+ // 当前组件名与原生tag或内建tag同名,对组件名进行转义
14
+ // json转义见:platform/json/wx/index.js fixComponentName
15
+ if (usingComponents.includes(newTag)) {
16
+ el.tag = newTag
17
+ }
18
+ return el
19
+ }
20
+ }
21
+ }
@@ -33,13 +33,13 @@ const switchComponent = require('./switch')
33
33
  const template = require('./template')
34
34
  const text = require('./text')
35
35
  const textarea = require('./textarea')
36
- const Nonsupport = require('./unsupported')
36
+ const unsupported = require('./unsupported')
37
37
  const video = require('./video')
38
38
  const view = require('./view')
39
39
  const webView = require('./web-view')
40
40
  const wxs = require('./wxs')
41
41
  const component = require('./component')
42
- const fixHTMLTag = require('./fix-html-tag')
42
+ const fixComponentName = require('./fix-component-name')
43
43
 
44
44
  module.exports = function getComponentConfigs ({ warn, error }) {
45
45
  /**
@@ -80,8 +80,8 @@ module.exports = function getComponentConfigs ({ warn, error }) {
80
80
 
81
81
  // 转换规则只需以微信为基准配置微信和支付宝的差异部分,比如微信和支付宝都支持但是写法不一致,或者微信支持而支付宝不支持的部分(抛出错误或警告)
82
82
  return [
83
- fixHTMLTag(),
84
- ...Nonsupport({ print }),
83
+ ...unsupported({ print }),
84
+ fixComponentName({ print }),
85
85
  ad({ print }),
86
86
  view({ print }),
87
87
  scrollView({ print }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.0",
3
+ "version": "2.9.3",
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": "91ac258dbf1d0a324a74cac606e2cc10ef557823"
85
+ "gitHead": "d0b4819fb5896f9796417f608eb06277dc5bdfaa"
86
86
  }
@@ -1,17 +0,0 @@
1
- const { isOriginTag, isBuildInTag } = require('../../../../utils/dom-tag-config')
2
-
3
- module.exports = function () {
4
- return {
5
- waterfall: true,
6
- test: (input) => isOriginTag(input) || isBuildInTag(input),
7
- // 处理原生tag
8
- web (tag, data = {}) {
9
- // @see packages/webpack-plugin/lib/platform/json/wx/index.js webHTMLTagProcesser
10
- const newTag = `mpx-com-${tag}`
11
- const usingComponents = data.usingComponents || []
12
- // 存在同名组件,则返回新tag
13
- if (usingComponents.includes(newTag)) return newTag
14
- return tag
15
- }
16
- }
17
- }