@mpxjs/webpack-plugin 2.8.49 → 2.8.51

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.
@@ -0,0 +1,101 @@
1
+ // These tag configs are shared between compiler-dom and runtime-dom, so they
2
+ // must be extracted in shared to avoid creating a dependency between the two.
3
+ const makeMap = require('./make-map')
4
+
5
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
6
+ const HTML_TAGS =
7
+ 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
8
+ 'header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
9
+ 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
10
+ 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
11
+ 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
12
+ 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
13
+ 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
14
+ 'option,output,progress,select,textarea,details,dialog,menu,' +
15
+ 'summary,template,blockquote,iframe,tfoot'
16
+
17
+ // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
18
+ const SVG_TAGS =
19
+ 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
20
+ 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
21
+ 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
22
+ 'feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
23
+ 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
24
+ 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
25
+ 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
26
+ 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
27
+ 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
28
+ 'text,textPath,title,tspan,unknown,use,view'
29
+
30
+ const VOID_TAGS =
31
+ 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr'
32
+
33
+ // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
34
+ // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
35
+ const isNonPhrasingTag = makeMap(
36
+ 'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
37
+ 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
38
+ 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
39
+ 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
40
+ 'title,tr,track'
41
+ )
42
+
43
+ const isRichTextTag = makeMap(
44
+ 'a,abbr,address,article,aside,b,bdi,bdo,big,blockquote,br,caption,' +
45
+ 'center,cite,code,col,colgroup,dd,del,div,dl,dt,em,fieldset,' +
46
+ 'font,footer,h1,h2,h3,h4,h5,h6,header,hr,i,img,ins,label,legend,' +
47
+ 'li,mark,nav,ol,p,pre,q,rt,ruby,s,section,small,span,strong,sub,sup,' +
48
+ 'table,tbody,td,tfoot,th,thead,tr,tt,u,ul'
49
+ )
50
+
51
+ const isUnaryTag = makeMap(
52
+ 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
53
+ 'link,meta,param,source,track,wbr'
54
+ )
55
+
56
+ // https://developers.weixin.qq.com/miniprogram/dev/component/
57
+ // 以后可能在框架中原生支持这些标签,所以需要进行判断
58
+ const isNativeMiniTag = makeMap(
59
+ 'cover-image,cover-view,match-media,movable-area,movable-view,' +
60
+ 'page-container,root-portal,scroll-view,swiper,swiper-item,view,' +
61
+ 'icon,progress,rich-text,text,button,checkbox,checkbox-group,editor,' +
62
+ 'form,input,keyboard-accessory,label,picker,picker-view,' +
63
+ 'picker-view-column,radio,radio-group,slider,switch,textarea,' +
64
+ 'grid-view,list-view,share-element,snapshot,span,sticky-header,' +
65
+ 'sticky-section,functional-page-navigator,navigator,audio,camera,' +
66
+ 'channel-live,channel-video,image,live-player,live-pusher,video,' +
67
+ 'voip-room,map,canvas,web-view,ad,ad-custom,official-account,' +
68
+ 'open-data,native-component,aria-component,page-meta'
69
+ )
70
+
71
+ const isSpace = makeMap('ensp,emsp,nbsp')
72
+
73
+ const isContWidth = makeMap('col,colgroup,img,table,td,th,tr')
74
+
75
+ const isContHeight = makeMap('img,td,th,tr')
76
+
77
+ const isContConRow = makeMap('td,th,tr')
78
+
79
+ const isHTMLTag = makeMap(HTML_TAGS)
80
+
81
+ const isSVGTag = makeMap(SVG_TAGS)
82
+
83
+ const isVoidTag = makeMap(VOID_TAGS)
84
+
85
+ // 是否为原始tag,包括 html tag 和小程序原生 tag
86
+ const isOriginTag = (tag) => isHTMLTag(tag) || isSVGTag(tag) || isVoidTag(tag) || isNativeMiniTag(tag)
87
+
88
+ module.exports = {
89
+ isOriginTag,
90
+ isHTMLTag,
91
+ isSVGTag,
92
+ isVoidTag,
93
+ isNonPhrasingTag,
94
+ isRichTextTag,
95
+ isUnaryTag,
96
+ isSpace,
97
+ isContWidth,
98
+ isContHeight,
99
+ isNativeMiniTag,
100
+ isContConRow
101
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Make a map and return a function for checking if a key
3
+ * is in that map.
4
+ */
5
+ module.exports = function makeMap (str, expectsLowerCase) {
6
+ const map = Object.create(null)
7
+ const list = str.split(',')
8
+ for (let i = 0; i < list.length; i++) {
9
+ map[list[i]] = true
10
+ }
11
+ return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]
12
+ }
@@ -23,8 +23,14 @@ function capitalToHyphen (v) {
23
23
  return ret
24
24
  }
25
25
 
26
+ // 删除空行
27
+ function trimBlankRow (str) {
28
+ return str.replace(/^\s*[\r\n]/gm, '')
29
+ }
30
+
26
31
  module.exports = {
27
32
  isCapital,
28
33
  isMustache,
29
- capitalToHyphen
34
+ capitalToHyphen,
35
+ trimBlankRow
30
36
  }
@@ -9,8 +9,10 @@ const parseComponent = require('../parser')
9
9
  const getJSONContent = require('../utils/get-json-content')
10
10
  const resolve = require('../utils/resolve')
11
11
  const createJSONHelper = require('../json-compiler/helper')
12
+ const getRulesRunner = require('../platform/index')
12
13
  const { RESOLVE_IGNORED_ERR } = require('../utils/const')
13
14
  const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
15
+ const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency')
14
16
 
15
17
  module.exports = function (json, {
16
18
  loaderContext,
@@ -26,6 +28,7 @@ module.exports = function (json, {
26
28
  const mpx = loaderContext.getMpx()
27
29
  const {
28
30
  mode,
31
+ srcMode,
29
32
  env,
30
33
  projectRoot
31
34
  } = mpx
@@ -75,12 +78,44 @@ module.exports = function (json, {
75
78
  })
76
79
  }
77
80
 
81
+ const { resourcePath } = parseRequest(loaderContext.resource)
82
+ const isApp = !(pagesMap[resourcePath] || componentsMap[resourcePath])
83
+
78
84
  if (!json) {
79
85
  return callback()
80
86
  }
81
87
  // 由于json需要提前读取在template处理中使用,src的场景已经在loader中处理了,此处无需考虑json.src的场景
82
88
  try {
83
89
  jsonObj = JSON5.parse(json.content)
90
+ // 处理runner
91
+ const rulesRunnerOptions = {
92
+ mode,
93
+ srcMode,
94
+ type: 'json',
95
+ waterfall: true,
96
+ warn: emitWarning,
97
+ error: emitError,
98
+ data: {
99
+ // polyfill global usingComponents & record globalComponents
100
+ globalComponents: mpx.usingComponents
101
+ }
102
+ }
103
+
104
+ if (!isApp) {
105
+ rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
106
+ }
107
+
108
+ const rulesRunner = getRulesRunner(rulesRunnerOptions)
109
+
110
+ if (rulesRunner) {
111
+ rulesRunner(jsonObj)
112
+ }
113
+ if (isApp) {
114
+ // 收集全局组件
115
+ Object.assign(mpx.usingComponents, jsonObj.usingComponents)
116
+ // 在 rulesRunner 运行后保存全局注册组件
117
+ loaderContext._module.addPresentationalDependency(new RecordGlobalComponentsDependency(mpx.usingComponents, loaderContext.context))
118
+ }
84
119
  } catch (e) {
85
120
  return callback(e)
86
121
  }
@@ -182,8 +182,10 @@ module.exports = function (script, {
182
182
  pagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
183
183
  }
184
184
  }
185
-
186
- if (pageCfg.isFirst) {
185
+ if (pagePath === jsonConfig.entryPagePath) {
186
+ firstPage = pagePath
187
+ }
188
+ if (!firstPage && pageCfg.isFirst) {
187
189
  firstPage = pagePath
188
190
  }
189
191
  })
@@ -2,23 +2,7 @@ const templateCompiler = require('../template-compiler/compiler')
2
2
  const genComponentTag = require('../utils/gen-component-tag')
3
3
  const addQuery = require('../utils/add-query')
4
4
  const parseRequest = require('../utils/parse-request')
5
- // const { matchCondition } = require('../utils/match-condition')
6
-
7
- function calculateRootEleChild (arr) {
8
- if (!arr) {
9
- return 0
10
- }
11
- return arr.reduce((total, item) => {
12
- if (item.type === 1) {
13
- if (item.tag === 'template') {
14
- total += calculateRootEleChild(item.children)
15
- } else {
16
- total += 1
17
- }
18
- }
19
- return total
20
- }, 0)
21
- }
5
+ const { matchCondition } = require('../utils/match-condition')
22
6
 
23
7
  module.exports = function (template, {
24
8
  loaderContext,
@@ -38,8 +22,9 @@ module.exports = function (template, {
38
22
  wxsContentMap,
39
23
  decodeHTMLText,
40
24
  externalClasses,
41
- checkUsingComponents
42
- // autoVirtualHostRules
25
+ checkUsingComponents,
26
+ proxyComponentEventsRules,
27
+ autoVirtualHostRules
43
28
  } = mpx
44
29
  const { resourcePath } = parseRequest(loaderContext.resource)
45
30
  const builtInComponentsMap = {}
@@ -72,6 +57,16 @@ module.exports = function (template, {
72
57
  }
73
58
  if (template.content) {
74
59
  const templateSrcMode = template.mode || srcMode
60
+
61
+ let proxyComponentEvents = null
62
+ for (const item of proxyComponentEventsRules) {
63
+ if (matchCondition(resourcePath, item)) {
64
+ const eventsRaw = item.events
65
+ proxyComponentEvents = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
66
+ break
67
+ }
68
+ }
69
+
75
70
  const { root, meta } = templateCompiler.parse(template.content, {
76
71
  warn: (msg) => {
77
72
  loaderContext.emitWarning(
@@ -101,9 +96,9 @@ module.exports = function (template, {
101
96
  // web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
102
97
  globalComponents: [],
103
98
  // web模式下实现抽象组件
104
- componentGenerics
105
- // todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
106
- // hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
99
+ componentGenerics,
100
+ proxyComponentEvents,
101
+ hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
107
102
  })
108
103
  if (meta.wxsModuleMap) {
109
104
  wxsModuleMap = meta.wxsModuleMap
@@ -123,18 +118,6 @@ module.exports = function (template, {
123
118
  if (meta.genericsInfo) {
124
119
  genericsInfo = meta.genericsInfo
125
120
  }
126
- // 输出H5有多个root element时, 使用mpx-root-view标签包裹
127
- // todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
128
- if (root.tag === 'temp-node') {
129
- const childLen = calculateRootEleChild(root.children)
130
- if (childLen >= 2) {
131
- root.tag = 'div'
132
- templateCompiler.addAttrs(root, [{
133
- name: 'class',
134
- value: 'mpx-root-view'
135
- }])
136
- }
137
- }
138
121
  return templateCompiler.serialize(root)
139
122
  }
140
123
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.49",
3
+ "version": "2.8.51",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -81,5 +81,5 @@
81
81
  "engines": {
82
82
  "node": ">=14.14.0"
83
83
  },
84
- "gitHead": "b399e81951df7094fb0a494ae877bcf4e6a2985b"
84
+ "gitHead": "7b9523688cc1cf8077d8705e64ea5a742dccff13"
85
85
  }
@@ -1,3 +0,0 @@
1
- <template>
2
- <view>局部构建兜底页面</view>
3
- </template>