@mpxjs/webpack-plugin 2.9.5 → 2.9.7

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/loader.js CHANGED
@@ -222,10 +222,6 @@ module.exports = function (content) {
222
222
  output += templateRes.output
223
223
  output += stylesRes.output
224
224
  output += jsonRes.output
225
- if (ctorType === 'app' && jsonRes.jsonObj.window && jsonRes.jsonObj.window.navigationBarTitleText) {
226
- mpx.appTitle = jsonRes.jsonObj.window.navigationBarTitleText
227
- }
228
-
229
225
  processScript(parts.script, {
230
226
  loaderContext,
231
227
  ctorType,
@@ -200,12 +200,20 @@ module.exports = function getSpec ({ warn, error }) {
200
200
  },
201
201
  {
202
202
  // 样式类名绑定
203
- test: /^wx:(class)$/,
204
- web ({ value }) {
205
- const parsed = parseMustacheWithContext(value)
203
+ test: /^(class|wx:class)$/,
204
+ web ({ value }, { el }) {
205
+ if (el.isClassParsed) {
206
+ return false
207
+ }
208
+ const classBinding = []
209
+ el.isClassParsed = true
210
+ el.attrsList.filter(item => this.test.test(item.name)).forEach((item) => {
211
+ const parsed = parseMustacheWithContext(item.value)
212
+ classBinding.push(parsed.result)
213
+ })
206
214
  return {
207
215
  name: ':class',
208
- value: parsed.result
216
+ value: `[${classBinding}]`
209
217
  }
210
218
  }
211
219
  },
@@ -178,7 +178,7 @@
178
178
  this.refresh()
179
179
  })
180
180
  const elementToObserve = document.querySelector('.mpx-movable-scroll-content')
181
- this.resizeObserver.observe(elementToObserve)
181
+ elementToObserve && this.resizeObserver.observe(elementToObserve)
182
182
  }
183
183
  },
184
184
  refresh () {
@@ -15,7 +15,13 @@
15
15
  export default {
16
16
  name: 'mpx-picker-view-column',
17
17
  props: {
18
- value: Array
18
+ value: Array,
19
+ scrollOptions: {
20
+ type: Object,
21
+ default: () => {
22
+ return {}
23
+ }
24
+ }
19
25
  },
20
26
  data() {
21
27
  return {
@@ -64,7 +70,9 @@
64
70
  rotate: -5,
65
71
  wheelWrapperClass: 'wheel-scroll'
66
72
  },
67
- probeType: 3
73
+ probeType: 3,
74
+ bindToWrapper: true,
75
+ ...this.scrollOptions
68
76
  })
69
77
  this.wheels[0].on('scrollStart', function () {
70
78
  if (this.pickerView) {
@@ -138,6 +138,12 @@
138
138
  fields: {
139
139
  type: String,
140
140
  default: 'day'
141
+ },
142
+ scrollOptions: {
143
+ type: Object,
144
+ default: () => {
145
+ return {}
146
+ }
141
147
  }
142
148
  },
143
149
  data () {
@@ -311,7 +317,9 @@
311
317
  wheelWrapperClass: 'wheel-scroll',
312
318
  wheelItemClass: 'wheel-item'
313
319
  },
314
- probeType: 3
320
+ probeType: 3,
321
+ bindToWrapper: true,
322
+ ...this.scrollOptions
315
323
  })
316
324
  if (this.mode === 'time' || this.mode === 'date') {
317
325
  this.wheels[i].on('scrollStart', function (i) {
@@ -47,7 +47,7 @@
47
47
  default: () => {
48
48
  return {}
49
49
  }
50
- },
50
+ }
51
51
  },
52
52
  data () {
53
53
  return {
@@ -212,7 +212,7 @@
212
212
  this.bs.scroller.hooks.on('beforeRefresh', () => {
213
213
  this.initLayerComputed()
214
214
  })
215
- this.bs.on('slideWillChange', (page) => {
215
+ this.bs.on('slidePageChanged', (page) => {
216
216
  this.currentIndex = this.vertical ? page.pageY : page.pageX
217
217
  this.$emit('change', getCustomEvent('change', {
218
218
  current: this.currentIndex,
@@ -1867,12 +1867,7 @@ function getVirtualHostRoot (options, meta) {
1867
1867
  }
1868
1868
  if (options.isPage) {
1869
1869
  if (mode === 'web') {
1870
- return createASTElement('div', [
1871
- {
1872
- name: 'class',
1873
- value: 'page'
1874
- }
1875
- ])
1870
+ return createASTElement('page', [])
1876
1871
  }
1877
1872
  }
1878
1873
  }
@@ -1,18 +1,22 @@
1
- // @mpxjs/webpack-plugin 2.7.x -> @mpxjs/core 2.7.x
2
- // @mpxjs/webpack-plugin 2.8.x -> @mpxjs/core 2.8.x
3
1
  const coreVersion = require('@mpxjs/core/package.json').version
4
- const packageName = require('../../package.json').name
5
- const packageVersion = require('../../package.json').version
2
+ const utilsVersion = require('@mpxjs/utils/package.json').version
3
+ const corePath = require.resolve('@mpxjs/core')
4
+ const utilsPath = require.resolve('@mpxjs/utils')
5
+ const semverLt = require('semver/functions/lt')
6
6
 
7
- if (packageVersion.slice(0, 3) !== coreVersion.slice(0, 3)) {
8
- const corePath = require.resolve('@mpxjs/core')
9
- const packagePath = require.resolve('../../package.json')
10
- throw new Error(
11
- `@mpxjs/core packages version mismatch:
12
- -@mpxjs/core@${coreVersion}(${corePath})
13
- -${packageName}@${packageVersion}(${packagePath})
14
- This may cause things to work incorrectly, Make sure to use the same minor version for both.
15
- For example: @mpxjs/core@2.7.x with @mpxjs/webpack-plugin@2.7.x
7
+ const leastCoreVersion = '2.8.59'
8
+ const leastUtilsVersion = '2.8.59'
9
+
10
+ function compare (version, leastVersion, npmName, npmPath) {
11
+ if (semverLt(version, leastVersion)) {
12
+ throw new Error(
13
+ `${npmName} packages version mismatch:
14
+ -${npmName}@${version}(${npmPath})
15
+ This may cause things to work incorrectly, Make sure the usage version is greater than ${leastVersion}.
16
16
  `
17
- )
17
+ )
18
+ }
18
19
  }
20
+
21
+ compare(coreVersion, leastCoreVersion, '@mpxjs/core', corePath)
22
+ compare(utilsVersion, leastUtilsVersion, '@mpxjs/utils', utilsPath)
@@ -1,7 +1,14 @@
1
1
  const addQuery = require('../utils/add-query')
2
2
  const normalize = require('../utils/normalize')
3
3
  const optionProcessorPath = normalize.lib('runtime/optionProcessor')
4
- const { buildComponentsMap, buildPagesMap, buildGlobalParams, shallowStringify, stringifyRequest, buildI18n } = require('./script-helper')
4
+ const {
5
+ buildComponentsMap,
6
+ buildPagesMap,
7
+ buildGlobalParams,
8
+ shallowStringify,
9
+ stringifyRequest,
10
+ buildI18n
11
+ } = require('./script-helper')
5
12
 
6
13
  module.exports = function (script, {
7
14
  loaderContext,
@@ -17,38 +24,57 @@ module.exports = function (script, {
17
24
  localPagesMap,
18
25
  resource
19
26
  }, callback) {
20
- const { i18n, webConfig } = loaderContext.getMpx()
21
-
22
- const { pagesMap, firstPage, globalTabBar } = buildPagesMap({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBarStr, jsonConfig })
27
+ const { i18n, webConfig, hasUnoCSS } = loaderContext.getMpx()
28
+ const { pagesMap, firstPage, globalTabBar } = buildPagesMap({
29
+ localPagesMap,
30
+ loaderContext,
31
+ tabBar,
32
+ tabBarMap,
33
+ tabBarStr,
34
+ jsonConfig
35
+ })
23
36
 
24
37
  const componentsMap = buildComponentsMap({ localComponentsMap, loaderContext })
25
38
 
26
39
  const scriptSrcMode = script ? script.mode || srcMode : srcMode
27
40
 
28
- let output = `\n import { processAppOption, getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
29
- import '@mpxjs/webpack-plugin/lib/runtime/base.styl'
30
- import Vue from 'vue'
31
- import VueRouter from 'vue-router'
32
- import Mpx from '@mpxjs/core'
33
- import App from ${stringifyRequest(loaderContext, addQuery(resource, { isApp: true }))}
34
- Vue.use(VueRouter)
35
- \n`
41
+ let output = ' import \'@mpxjs/webpack-plugin/lib/runtime/base.styl\'\n'
42
+ // hasUnoCSS由@mpxjs/unocss-plugin注入
43
+ if (hasUnoCSS) {
44
+ output += ' import \'uno.css\'\n'
45
+ }
46
+ output += ` import Vue from 'vue'
47
+ import VueRouter from 'vue-router'
48
+ import Mpx from '@mpxjs/core'
49
+ import App from ${stringifyRequest(loaderContext, addQuery(resource, { isApp: true }))}
50
+ import { processAppOption, getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
51
+ Vue.use(VueRouter)\n`
36
52
 
37
53
  if (i18n) {
38
54
  output += buildI18n({ i18n, loaderContext })
39
55
  }
40
56
 
41
- output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, jsonConfig, webConfig, isMain: true, globalTabBar })
42
- output += `export default processAppOption({
43
- App,
44
- tabBarMap: ${JSON.stringify(tabBarMap)},
45
- firstPage: ${JSON.stringify(firstPage)},
46
- pagesMap: ${shallowStringify(pagesMap)},
47
- componentsMap: ${shallowStringify(componentsMap)},
48
- Vue,
49
- VueRouter,
50
- webConfig: ${JSON.stringify(webConfig)}
51
- })`
57
+ output += buildGlobalParams({
58
+ moduleId,
59
+ scriptSrcMode,
60
+ loaderContext,
61
+ isProduction,
62
+ jsonConfig,
63
+ webConfig,
64
+ isMain: true,
65
+ globalTabBar
66
+ })
67
+ output += `
68
+ export default processAppOption({
69
+ App,
70
+ tabBarMap: ${JSON.stringify(tabBarMap)},
71
+ firstPage: ${JSON.stringify(firstPage)},
72
+ pagesMap: ${shallowStringify(pagesMap)},
73
+ componentsMap: ${shallowStringify(componentsMap)},
74
+ Vue,
75
+ VueRouter,
76
+ webConfig: ${JSON.stringify(webConfig)}
77
+ })\n`
52
78
 
53
79
  callback(null, {
54
80
  output
@@ -75,7 +75,8 @@ module.exports = function (script, {
75
75
 
76
76
  content += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction })
77
77
  content += getRequireScript({ ctorType, script, loaderContext })
78
- content += ` export default processComponentOption({
78
+ content += `
79
+ export default processComponentOption({
79
80
  option: global.__mpxOptionsMap[${JSON.stringify(moduleId)}],
80
81
  ctorType: ${JSON.stringify(ctorType)},
81
82
  outputPath: ${JSON.stringify(outputPath)},
@@ -85,12 +86,11 @@ module.exports = function (script, {
85
86
  componentGenerics: ${JSON.stringify(componentGenerics)},
86
87
  genericsInfo: ${JSON.stringify(genericsInfo)},
87
88
  mixin: getWxsMixin(wxsModules),
88
- hasApp: ${hasApp}`
89
- content += '\n })\n'
89
+ hasApp: ${hasApp}
90
+ })\n`
90
91
  return content
91
92
  }
92
93
  })
93
- output += '\n'
94
94
 
95
95
  callback(null, {
96
96
  output
@@ -81,10 +81,11 @@ function buildPagesMap ({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBa
81
81
  })
82
82
  }
83
83
  if (tabBarStr && tabBarPagesMap) {
84
- globalTabBar += ` global.__tabBar = ${tabBarStr}
85
- Vue.observable(global.__tabBar)
86
- // @ts-ignore
87
- global.__tabBarPagesMap = ${shallowStringify(tabBarPagesMap)}\n`
84
+ globalTabBar += `
85
+ global.__tabBar = ${tabBarStr}
86
+ Vue.observable(global.__tabBar)
87
+ // @ts-ignore
88
+ global.__tabBarPagesMap = ${shallowStringify(tabBarPagesMap)}\n`
88
89
  }
89
90
  Object.keys(localPagesMap).forEach((pagePath) => {
90
91
  const pageCfg = localPagesMap[pagePath]
@@ -125,29 +126,30 @@ function getRequireScript ({ ctorType, script, loaderContext }) {
125
126
  function buildGlobalParams ({ moduleId, scriptSrcMode, loaderContext, isProduction, jsonConfig, webConfig, isMain, globalTabBar }) {
126
127
  let content = ''
127
128
  if (isMain) {
128
- content += `global.getApp = function(){}
129
- global.getCurrentPages = function () {
130
- if (!(typeof window !== 'undefined')) {
131
- console.error('[Mpx runtime error]: Dangerous API! global.getCurrentPages is running in non browser environment, It may cause some problems, please use this method with caution')
132
- }
133
- const router = global.__mpxRouter
134
- if(!router) return []
135
- // @ts-ignore
136
- return (router.lastStack || router.stack).map(item => {
137
- let page
138
- const vnode = item.vnode
139
- if (vnode && vnode.componentInstance) {
140
- page = vnode.tag.endsWith('mpx-tab-bar-container') ? vnode.componentInstance.$refs.tabBarPage : vnode.componentInstance
141
- }
142
- return page || { route: item.path.slice(1) }
143
- })
129
+ content += `
130
+ global.getApp = function(){}
131
+ global.getCurrentPages = function () {
132
+ if (!(typeof window !== 'undefined')) {
133
+ console.error('[Mpx runtime error]: Dangerous API! global.getCurrentPages is running in non browser environment, It may cause some problems, please use this method with caution')
144
134
  }
145
- global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
146
- global.__mpxGenericsMap = {}
147
- global.__mpxOptionsMap = {}
148
- global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
149
- global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
150
- global.__mpxTransRpxFn = ${webConfig.transRpxFn}\n`
135
+ const router = global.__mpxRouter
136
+ if(!router) return []
137
+ // @ts-ignore
138
+ return (router.lastStack || router.stack).map(item => {
139
+ let page
140
+ const vnode = item.vnode
141
+ if (vnode && vnode.componentInstance) {
142
+ page = vnode.tag.endsWith('mpx-tab-bar-container') ? vnode.componentInstance.$refs.tabBarPage : vnode.componentInstance
143
+ }
144
+ return page || { route: item.path.slice(1) }
145
+ })
146
+ }
147
+ global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
148
+ global.__mpxGenericsMap = {}
149
+ global.__mpxOptionsMap = {}
150
+ global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
151
+ global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
152
+ global.__mpxTransRpxFn = ${webConfig.transRpxFn}\n`
151
153
  if (globalTabBar) {
152
154
  content += globalTabBar
153
155
  }
@@ -164,9 +166,10 @@ function buildGlobalParams ({ moduleId, scriptSrcMode, loaderContext, isProducti
164
166
  function buildI18n ({ i18n, loaderContext }) {
165
167
  let i18nContent = ''
166
168
  const i18nObj = Object.assign({}, i18n)
167
- i18nContent += ` import VueI18n from 'vue-i18n'
168
- import { createI18n } from 'vue-i18n-bridge'
169
- Vue.use(VueI18n , { bridge: true })\n`
169
+ i18nContent += `
170
+ import VueI18n from 'vue-i18n'
171
+ import { createI18n } from 'vue-i18n-bridge'
172
+ Vue.use(VueI18n , { bridge: true })\n`
170
173
  const requestObj = {}
171
174
  const i18nKeys = ['messages', 'dateTimeFormats', 'numberFormats']
172
175
  i18nKeys.forEach((key) => {
@@ -179,10 +182,11 @@ function buildI18n ({ i18n, loaderContext }) {
179
182
  Object.keys(requestObj).forEach((key) => {
180
183
  i18nContent += ` i18nCfg.${key} = require(${requestObj[key]})\n`
181
184
  })
182
- i18nContent += ' i18nCfg.legacy = false\n'
183
- i18nContent += ` const i18n = createI18n(i18nCfg, VueI18n)
184
- Vue.use(i18n)
185
- Mpx.i18n = i18n\n`
185
+ i18nContent += `
186
+ i18nCfg.legacy = false
187
+ const i18n = createI18n(i18nCfg, VueI18n)
188
+ Vue.use(i18n)
189
+ Mpx.i18n = i18n\n`
186
190
  return i18nContent
187
191
  }
188
192
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.5",
3
+ "version": "2.9.7",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -54,6 +54,7 @@
54
54
  "postcss-modules-values": "^4.0.0",
55
55
  "postcss-selector-parser": "^6.0.8",
56
56
  "postcss-value-parser": "^4.0.2",
57
+ "semver": "^7.5.4",
57
58
  "source-list-map": "^2.0.0",
58
59
  "video.js": "^8.6.0"
59
60
  },
@@ -82,5 +83,5 @@
82
83
  "engines": {
83
84
  "node": ">=14.14.0"
84
85
  },
85
- "gitHead": "beefb0935f3aa9d3605dd6f31b8cd37094186488"
86
+ "gitHead": "baebbdc18806ba54ef705da6620eb274b5ac394b"
86
87
  }