@mpxjs/webpack-plugin 2.8.0-beta.4 → 2.8.0

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.
package/lib/extractor.js CHANGED
@@ -62,7 +62,8 @@ module.exports.pitch = async function (remainingRequest) {
62
62
 
63
63
  const extractedInfo = {
64
64
  content,
65
- index
65
+ // isStatic时不需要关注引用索引
66
+ index: isStatic ? 0 : index
66
67
  }
67
68
 
68
69
  this.emitFile(file, '', undefined, {
package/lib/index.js CHANGED
@@ -148,7 +148,7 @@ class MpxWebpackPlugin {
148
148
  options.auditResource = options.auditResource || false
149
149
  options.decodeHTMLText = options.decodeHTMLText || false
150
150
  options.i18n = options.i18n || null
151
- options.checkUsingComponents = options.checkUsingComponents || false
151
+ options.checkUsingComponentsRules = options.checkUsingComponentsRules || (options.checkUsingComponents ? { include: () => true } : { exclude: () => true })
152
152
  options.reportSize = options.reportSize || null
153
153
  options.pathHashMode = options.pathHashMode || 'absolute'
154
154
  options.forceDisableBuiltInLoader = options.forceDisableBuiltInLoader || false
@@ -567,7 +567,7 @@ class MpxWebpackPlugin {
567
567
  tabBarMap: {},
568
568
  defs: processDefs(this.options.defs),
569
569
  i18n: this.options.i18n,
570
- checkUsingComponents: this.options.checkUsingComponents,
570
+ checkUsingComponentsRules: this.options.checkUsingComponentsRules,
571
571
  forceDisableBuiltInLoader: this.options.forceDisableBuiltInLoader,
572
572
  appTitle: 'Mpx homepage',
573
573
  attributes: this.options.attributes,
@@ -1423,11 +1423,11 @@ try {
1423
1423
  let mpxStyleLoaderIndex = -1
1424
1424
  loaders.forEach((loader, index) => {
1425
1425
  const currentLoader = toPosix(loader.loader)
1426
- if (currentLoader.includes('css-loader')) {
1426
+ if (currentLoader.includes('css-loader') && cssLoaderIndex === -1) {
1427
1427
  cssLoaderIndex = index
1428
- } else if (currentLoader.includes('vue-loader/lib/loaders/stylePostLoader')) {
1428
+ } else if (currentLoader.includes('vue-loader/lib/loaders/stylePostLoader') && vueStyleLoaderIndex === -1) {
1429
1429
  vueStyleLoaderIndex = index
1430
- } else if (currentLoader.includes(styleCompilerPath)) {
1430
+ } else if (currentLoader.includes(styleCompilerPath) && mpxStyleLoaderIndex === -1) {
1431
1431
  mpxStyleLoaderIndex = index
1432
1432
  }
1433
1433
  })
@@ -480,8 +480,9 @@ module.exports = function (content) {
480
480
  delete tabBar.custom
481
481
  return callback()
482
482
  }
483
+ if (err) return callback(err)
483
484
  tabBar.custom = entry // hack for javascript parser call hook.
484
- callback(err)
485
+ callback()
485
486
  })
486
487
  } else {
487
488
  callback()
package/lib/loader.js CHANGED
@@ -100,6 +100,7 @@ module.exports = function (content) {
100
100
  const isNative = false
101
101
 
102
102
  let usingComponents = [].concat(Object.keys(mpx.usingComponents))
103
+ let componentPlaceholder = []
103
104
 
104
105
  let componentGenerics = {}
105
106
 
@@ -110,6 +111,9 @@ module.exports = function (content) {
110
111
  fixUsingComponent(ret.usingComponents, mode)
111
112
  usingComponents = usingComponents.concat(Object.keys(ret.usingComponents))
112
113
  }
114
+ if (ret.componentPlaceholder) {
115
+ componentPlaceholder = componentPlaceholder.concat(Object.values(ret.componentPlaceholder))
116
+ }
113
117
  if (ret.componentGenerics) {
114
118
  componentGenerics = Object.assign({}, ret.componentGenerics)
115
119
  }
@@ -278,7 +282,8 @@ module.exports = function (content) {
278
282
  hasComment,
279
283
  isNative,
280
284
  moduleId,
281
- usingComponents
285
+ usingComponents,
286
+ componentPlaceholder
282
287
  // 添加babel处理渲染函数中可能包含的...展开运算符
283
288
  // 由于...运算符应用范围极小以及babel成本极高,先关闭此特性后续看情况打开
284
289
  // needBabel: true
@@ -18,8 +18,8 @@
18
18
  <div class="wheel" v-for="(data, index) in pickerData" :key="index">
19
19
  <ul class="wheel-scroll">
20
20
  <li
21
- v-for="item in data" :key="item"
22
- class="wheel-item">{{item}}
21
+ v-for="item in data" :key="item"
22
+ class="wheel-item">{{item}}
23
23
  </li>
24
24
  </ul>
25
25
  </div>
@@ -39,10 +39,10 @@
39
39
  import { type } from '../../utils'
40
40
  import { getCustomEvent } from './getInnerListeners'
41
41
 
42
- const startYear = 1970
42
+ const startYear = 1900
43
43
  const modeOptions = {
44
44
  time: [23, 59],
45
- date: [130, 11, 30]
45
+ date: [200, 11, 30]
46
46
  }
47
47
 
48
48
  BScroll.use(Wheel)
@@ -73,7 +73,7 @@
73
73
  let months = []
74
74
  let days = []
75
75
 
76
- for (let i = 0; i <= 130; i++) {
76
+ for (let i = 0; i <= 200; i++) {
77
77
  years.push(`${startYear + i}年`)
78
78
  }
79
79
  if (fields === 'year') {
@@ -127,11 +127,17 @@
127
127
  }
128
128
  }
129
129
  },
130
- start: String,
131
- end: String,
130
+ start: {
131
+ type: String,
132
+ default: '1970-01-01'
133
+ },
134
+ end: {
135
+ type: String,
136
+ default: '2100-01-01'
137
+ },
132
138
  fields: {
133
139
  type: String,
134
- value: 'day'
140
+ default: 'day'
135
141
  }
136
142
  },
137
143
  data () {
@@ -794,10 +794,14 @@ function parse (template, options) {
794
794
  Array.isArray(val.errorArray) && val.errorArray.forEach(item => error$1(item))
795
795
  })
796
796
 
797
- if (!tagNames.has('component')) {
797
+ if (!tagNames.has('component') && options.checkUsingComponents) {
798
+ const arr = []
798
799
  options.usingComponents.forEach((item) => {
799
- if (!tagNames.has(item) && !options.globalComponents.includes(item) && options.checkUsingComponents) warn$1(`${item}注册了,但是未被对应的模板引用,建议删除!`)
800
+ if (!tagNames.has(item) && !options.globalComponents.includes(item) && !options.componentPlaceholder.includes(item)) {
801
+ arr.push(item)
802
+ }
800
803
  })
804
+ arr.length && warn$1(`\n ${options.filePath} \n 组件 ${arr.join(' | ')} 注册了,但是未被对应的模板引用,建议删除!`)
801
805
  }
802
806
 
803
807
  return {
@@ -1914,7 +1918,7 @@ function postProcessTemplate (el) {
1914
1918
  }
1915
1919
  }
1916
1920
 
1917
- const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd')
1921
+ const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,noMode')
1918
1922
 
1919
1923
  const wrapRE = /^\((.*)\)$/
1920
1924
 
@@ -1946,32 +1950,46 @@ function processAtMode (el) {
1946
1950
  return
1947
1951
  }
1948
1952
 
1949
- const conditionMap = {}
1950
-
1953
+ const conditionMap = new Map()
1951
1954
  modeStr.split('|').forEach(item => {
1952
1955
  const arr = item.split(':')
1953
- const key = arr[0] || mode
1954
- conditionMap[key] = arr.slice(1)
1956
+ const key = arr[0] || 'noMode'
1957
+ conditionMap.set(key, arr.slice(1))
1955
1958
  })
1956
1959
 
1957
- const modeArr = Object.keys(conditionMap)
1960
+ const modeArr = [...conditionMap.keys()]
1958
1961
 
1959
1962
  if (modeArr.every(i => isValidMode(i))) {
1960
1963
  const attrValue = getAndRemoveAttr(el, attrName).val
1961
1964
  const replacedAttrName = attrArr.join('@')
1962
-
1963
1965
  const processedAttr = { name: replacedAttrName, value: attrValue }
1964
- if (modeArr.includes(mode) && (!conditionMap[mode].length || conditionMap[mode].includes(env))) {
1965
- if (!replacedAttrName) {
1966
- el._atModeStatus = 'match'
1966
+
1967
+ for (const [defineMode, defineEnvArr] of conditionMap.entries()) {
1968
+ if (defineMode === 'noMode' || defineMode === mode) {
1969
+ // 命中 env 规则(没有定义env 或者定义的envArr包含当前env)
1970
+ if (!defineEnvArr.length || defineEnvArr.includes(env)) {
1971
+ el._atModeStatus = ''
1972
+ if (!replacedAttrName) {
1973
+ // 若defineMode 为 noMode,则不论是element,还是attr,都需要经过规则转换
1974
+ if (defineMode !== 'noMode') {
1975
+ el._atModeStatus = 'match'
1976
+ }
1977
+ } else {
1978
+ // 如果命中了指定的mode,则先存在el上,等跑完转换后再挂回去
1979
+ el.noTransAttrs ? el.noTransAttrs.push(processedAttr) : el.noTransAttrs = [processedAttr]
1980
+ }
1981
+ // 命中mode,命中env,完成匹配,直接退出
1982
+ break
1983
+ } else if (!replacedAttrName) {
1984
+ // 命中mode规则,没有命中当前env规则,设置为 'mismatch'
1985
+ el._atModeStatus = 'mismatch'
1986
+ }
1987
+ } else if (!replacedAttrName) {
1988
+ // 没有命中当前mode规则,设置为 'mismatch'
1989
+ el._atModeStatus = 'mismatch'
1967
1990
  } else {
1968
- // 如果命中了指定的mode,则先存在el上,等跑完转换后再挂回去
1969
- el.noTransAttrs ? el.noTransAttrs.push(processedAttr) : el.noTransAttrs = [processedAttr]
1991
+ // 如果没命中指定的mode,则该属性删除
1970
1992
  }
1971
- } else if (!replacedAttrName) {
1972
- el._atModeStatus = 'mismatch'
1973
- } else {
1974
- // 如果没命中指定的mode,则该属性删除
1975
1993
  }
1976
1994
  }
1977
1995
  })
@@ -21,6 +21,7 @@ module.exports = function (raw) {
21
21
  const componentsMap = mpx.componentsMap[packageName]
22
22
  const wxsContentMap = mpx.wxsContentMap
23
23
  const usingComponents = queryObj.usingComponents || []
24
+ const componentPlaceholder = queryObj.componentPlaceholder || []
24
25
  const hasComment = queryObj.hasComment
25
26
  const isNative = queryObj.isNative
26
27
  const hasScoped = queryObj.hasScoped
@@ -42,6 +43,7 @@ module.exports = function (raw) {
42
43
  warn,
43
44
  error,
44
45
  usingComponents,
46
+ componentPlaceholder,
45
47
  hasComment,
46
48
  isNative,
47
49
  isComponent: !!componentsMap[resourcePath],
@@ -56,7 +58,7 @@ module.exports = function (raw) {
56
58
  // 这里需传递resourcePath和wxsContentMap保持一致
57
59
  filePath: resourcePath,
58
60
  i18n,
59
- checkUsingComponents: mpx.checkUsingComponents,
61
+ checkUsingComponents: matchCondition(resourcePath, mpx.checkUsingComponentsRules),
60
62
  globalComponents: Object.keys(mpx.usingComponents),
61
63
  forceProxyEvent: matchCondition(resourcePath, mpx.forceProxyEventRules),
62
64
  hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.0-beta.4",
3
+ "version": "2.8.0",
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": "7a3dd6c2d0fceb31ee035e85b7f11091e31409d3"
85
+ "gitHead": "c52503f66f8ab3832e7ec94357d9e1586fbc4460"
86
86
  }