@mpxjs/webpack-plugin 2.6.107 → 2.6.111

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/index.js CHANGED
@@ -363,10 +363,12 @@ class MpxWebpackPlugin {
363
363
  compilation.errors.push(e)
364
364
  }
365
365
  })
366
- if (packageRoot) {
367
- module.request = addQuery(module.request, { packageRoot })
368
- module.resource = addQuery(module.resource, { packageRoot })
369
- }
366
+ const queryObj = {}
367
+ if (packageRoot) queryObj.packageRoot = packageRoot
368
+ // todo 后续可以考虑用module.layer来隔离独立分包的模块
369
+ if (isIndependent) queryObj.isIndependent = true
370
+ module.request = addQuery(module.request, queryObj)
371
+ module.resource = addQuery(module.resource, queryObj)
370
372
  }
371
373
  }
372
374
 
@@ -413,6 +415,7 @@ class MpxWebpackPlugin {
413
415
  // 当前机制下分包处理队列在app.json的json-compiler中进行,由于addEntry回调特性,无法保障app.js中引用的模块都被标记为主包,故重写processModuleDependencies获取app.js及其所有依赖处理完成的时机,在这之后再执行分包处理队列
414
416
  appScriptRawRequest: '',
415
417
  appScriptPromise: null,
418
+ appScriptPromiseResolve: null,
416
419
  // 记录entry依赖关系,用于体积分析
417
420
  entryNodesMap: {},
418
421
  // 记录entryModule与entryNode的对应关系,用于体积分析
@@ -590,12 +593,10 @@ class MpxWebpackPlugin {
590
593
  if (module.rawRequest === mpx.appScriptRawRequest) {
591
594
  // 避免模块request重名,只对第一次匹配到的模块进行代理
592
595
  mpx.appScriptRawRequest = ''
593
- mpx.appScriptPromise = new Promise((resolve) => {
594
- proxyedCallback = (err) => {
595
- resolve()
596
- return callback(err)
597
- }
598
- })
596
+ proxyedCallback = (err) => {
597
+ mpx.appScriptPromiseResolve()
598
+ return callback(err)
599
+ }
599
600
  }
600
601
  return rawProcessModuleDependencies.apply(compilation, [module, proxyedCallback])
601
602
  }
package/lib/loader.js CHANGED
@@ -38,7 +38,6 @@ module.exports = function (content) {
38
38
  const localSrcMode = queryObj.mode
39
39
  const srcMode = localSrcMode || globalSrcMode
40
40
  const vueContentCache = mpx.vueContentCache
41
- const webRouteMode = mpx.webConfig.routeMode || 'hash'
42
41
  const autoScope = matchCondition(resourcePath, mpx.autoScopeRules)
43
42
 
44
43
  // 支持资源query传入page或component支持页面/组件单独编译
@@ -245,7 +244,6 @@ module.exports = function (content) {
245
244
  i18n,
246
245
  componentGenerics,
247
246
  projectRoot,
248
- webRouteMode,
249
247
  jsonConfig: jsonRes.jsonObj,
250
248
  componentId: queryObj.componentId || '',
251
249
  tabBarMap: jsonRes.tabBarMap,
@@ -275,9 +273,8 @@ module.exports = function (content) {
275
273
  if (!isProduction) {
276
274
  globalInjectCode += `global.currentResource = ${JSON.stringify(filePath)}\n`
277
275
  }
278
- if (ctorType === 'app' && i18n && !mpx.forceDisableInject) {
279
- globalInjectCode += `global.i18n = ${JSON.stringify({ locale: i18n.locale, version: 0 })}\n`
280
276
 
277
+ if (i18n && (ctorType === 'app' || (ctorType === 'page' && queryObj.isIndependent)) && !mpx.forceDisableInject) {
281
278
  const i18nMethodsVar = 'i18nMethods'
282
279
  const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
283
280
  const i18nWxsLoaderPath = normalize.lib('wxs/wxs-i18n-loader.js')
@@ -295,7 +292,10 @@ module.exports = function (content) {
295
292
  })
296
293
  this._module.addVariable(i18nMethodsVar, expression, deps)
297
294
 
298
- globalInjectCode += `global.i18nMethods = ${i18nMethodsVar}\n`
295
+ globalInjectCode += `if (!global.i18n) {
296
+ global.i18n = ${JSON.stringify({ locale: i18n.locale, version: 0 })}
297
+ global.i18nMethods = ${i18nMethodsVar}
298
+ }\n`
299
299
  }
300
300
  // 注入构造函数
301
301
  let ctor = 'App'
@@ -331,7 +331,12 @@ module.exports = function (content) {
331
331
  }
332
332
  if (scriptRequestString) {
333
333
  output += 'export * from ' + scriptRequestString + '\n\n'
334
- if (ctorType === 'app') mpx.appScriptRawRequest = JSON.parse(scriptRequestString)
334
+ if (ctorType === 'app') {
335
+ mpx.appScriptRawRequest = JSON.parse(scriptRequestString)
336
+ mpx.appScriptPromise = new Promise((resolve) => {
337
+ mpx.appScriptPromiseResolve = resolve
338
+ })
339
+ }
335
340
  }
336
341
  } else {
337
342
  switch (ctorType) {
@@ -73,7 +73,12 @@ module.exports = function getSpec ({ warn, error }) {
73
73
  swan: deletePath()
74
74
  },
75
75
  {
76
- test: 'onReachBottomDistance|disableScroll',
76
+ test: 'onReachBottomDistance',
77
+ qq: deletePath(),
78
+ jd: deletePath()
79
+ },
80
+ {
81
+ test: 'disableScroll',
77
82
  ali: deletePath(),
78
83
  qq: deletePath(),
79
84
  jd: deletePath()
@@ -84,7 +89,7 @@ module.exports = function getSpec ({ warn, error }) {
84
89
  swan: deletePath()
85
90
  },
86
91
  {
87
- test: 'navigationBarTextStyle|navigationStyle|backgroundColor|backgroundTextStyle',
92
+ test: 'navigationBarTextStyle|navigationStyle|backgroundTextStyle',
88
93
  ali: deletePath()
89
94
  },
90
95
  {
@@ -44,7 +44,7 @@ module.exports = function ({ print }) {
44
44
  // 如果是个变量,报warning~
45
45
  aliPropLog(attr)
46
46
  } else {
47
- let supportedList = ['navigate', 'redirect', 'switchTab', 'navigateBack', 'reLaunch']
47
+ let supportedList = ['navigate', 'redirect', 'switchTab', 'navigateBack', 'reLaunch', 'exit']
48
48
  if (supportedList.indexOf(attr.value) === -1) {
49
49
  aliValueLogError(attr)
50
50
  }
@@ -12,7 +12,6 @@ export default function processOption (
12
12
  componentGenerics,
13
13
  genericsInfo,
14
14
  mixin,
15
- webRouteMode,
16
15
  Vue,
17
16
  VueRouter,
18
17
  i18n
@@ -26,23 +25,6 @@ export default function processOption (
26
25
  }
27
26
  }
28
27
 
29
- // 注册v-ex-classes自定义指令处理externalClasses
30
- Vue.directive('ex-classes', (el, binding, vnode) => {
31
- const context = vnode.context
32
- if (context) {
33
- const externalClasses = context.$options.externalClasses || []
34
- const classList = el.classList
35
- binding.value.forEach((className) => {
36
- const actualExternalClassNames = context.$attrs[className]
37
- if (externalClasses.indexOf(className) !== -1 && actualExternalClassNames) {
38
- classList.remove(className)
39
- actualExternalClassNames.split(/\s+/).forEach((actualExternalClassName) => {
40
- if (actualExternalClassName) classList.add(actualExternalClassName)
41
- })
42
- }
43
- })
44
- }
45
- })
46
28
  Vue.directive('animation', (el, binding) => {
47
29
  const newActions = binding && binding.value && binding.value.actions
48
30
  if (el.actions === newActions) {
@@ -122,8 +104,9 @@ export default function processOption (
122
104
  redirect: '/' + firstPage
123
105
  })
124
106
  }
107
+ const webRouteConfig = global.__mpx.config.webRouteConfig
125
108
  global.__mpxRouter = option.router = new VueRouter({
126
- mode: webRouteMode,
109
+ ...webRouteConfig,
127
110
  routes: routes
128
111
  })
129
112
  global.__mpxRouter.stack = []
@@ -93,7 +93,7 @@ function isDef (v) {
93
93
  return v !== undefined && v !== null
94
94
  }
95
95
 
96
- function stringifyClass (value) {
96
+ function stringifyDynamicClass (value) {
97
97
  if (!value) return ''
98
98
  if (likeArray(value)) {
99
99
  return stringifyArray(value)
@@ -111,7 +111,7 @@ function stringifyArray (value) {
111
111
  var res = ''
112
112
  var stringified
113
113
  for (var i = 0; i < value.length; i++) {
114
- if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') {
114
+ if (isDef(stringified = stringifyDynamicClass(value[i])) && stringified !== '') {
115
115
  if (res) res += ' '
116
116
  res += stringified
117
117
  }
@@ -207,7 +207,7 @@ module.exports = {
207
207
  if (typeof staticClass !== 'string') {
208
208
  return console.log('Template attr class must be a string!')
209
209
  }
210
- return concat(staticClass, stringifyClass(dynamicClass))
210
+ return concat(staticClass, stringifyDynamicClass(dynamicClass))
211
211
  },
212
212
  stringifyStyle: function (staticStyle, dynamicStyle) {
213
213
  var normalizedDynamicStyle = normalizeDynamicStyle(dynamicStyle)
@@ -2,7 +2,7 @@ const getMainCompilation = require('../utils/get-main-compilation')
2
2
  const postcss = require('postcss')
3
3
  const loaderUtils = require('loader-utils')
4
4
  const loadPostcssConfig = require('./load-postcss-config')
5
- const { MPX_ROOT_VIEW } = require('../staticConfig')
5
+ const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../staticConfig')
6
6
  const trim = require('./plugins/trim')
7
7
  const rpx = require('./plugins/rpx')
8
8
  const vw = require('./plugins/vw')
@@ -91,7 +91,7 @@ module.exports = function (css, map) {
91
91
  .then(result => {
92
92
  // ali环境添加全局样式抹平root差异
93
93
  if (mpx.mode === 'ali' && isApp) {
94
- result.css += `\n.${MPX_ROOT_VIEW} { display: inline; line-height: normal; }\n`
94
+ result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\n.${MPX_APP_MODULE_ID} { line-height: normal }`
95
95
  }
96
96
  if (result.messages) {
97
97
  result.messages.forEach(({ type, file }) => {
@@ -1853,25 +1853,65 @@ function processAliExternalClassesHack (el, options) {
1853
1853
  }
1854
1854
  }
1855
1855
 
1856
+ // externalClasses只能模拟静态传递
1856
1857
  function processWebExternalClassesHack (el, options) {
1857
- // todo 处理scoped的情况, 处理组件多层传递externalClass的情况,通过externalClass属性传递实际类名及scopeId信息,可以使用特殊的类名形式代表scopeId,如#idstring
1858
- let staticClass = el.attrsMap['class']
1859
- let dynamicClass = el.attrsMap[':class']
1860
- if (staticClass || dynamicClass) {
1861
- const externalClasses = []
1858
+ const staticClass = getAndRemoveAttr(el, 'class').val
1859
+ if (staticClass) {
1860
+ const classNames = staticClass.split(/\s+/)
1861
+ const replacements = []
1862
1862
  options.externalClasses.forEach((className) => {
1863
- const reg = new RegExp('\\b' + className + '\\b')
1864
- if (reg.test(staticClass) || reg.test(dynamicClass)) {
1865
- externalClasses.push(className)
1863
+ const index = classNames.indexOf(className)
1864
+ if (index > -1) {
1865
+ replacements.push(`$attrs[${JSON.stringify(className)}]`)
1866
+ classNames.splice(index, 1)
1866
1867
  }
1867
1868
  })
1868
- if (externalClasses.length) {
1869
+
1870
+ if (classNames.length) {
1871
+ addAttrs(el, [{
1872
+ name: 'class',
1873
+ value: classNames.join(' ')
1874
+ }])
1875
+ }
1876
+
1877
+ if (replacements.length) {
1878
+ const dynamicClass = getAndRemoveAttr(el, ':class').val
1879
+ if (dynamicClass) replacements.push(dynamicClass)
1880
+
1869
1881
  addAttrs(el, [{
1870
- name: 'v-ex-classes',
1871
- value: JSON.stringify(externalClasses)
1882
+ name: ':class',
1883
+ value: `[${replacements.join(',')}]`
1872
1884
  }])
1873
1885
  }
1874
1886
  }
1887
+
1888
+ // 处理externalClasses多层透传
1889
+ const isComponent = isComponentNode(el, options)
1890
+ if (isComponent) {
1891
+ options.externalClasses.forEach((classLikeAttrName) => {
1892
+ let classLikeAttrValue = getAndRemoveAttr(el, classLikeAttrName).val
1893
+ if (classLikeAttrValue) {
1894
+ const classNames = classLikeAttrValue.split(/\s+/)
1895
+ const replacements = []
1896
+ options.externalClasses.forEach((className) => {
1897
+ const index = classNames.indexOf(className)
1898
+ if (index > -1) {
1899
+ replacements.push(`$attrs[${JSON.stringify(className)}]`)
1900
+ classNames.splice(index, 1)
1901
+ }
1902
+ })
1903
+
1904
+ if (classNames.length) {
1905
+ replacements.unshift(JSON.stringify(classNames.join(' ')))
1906
+ }
1907
+
1908
+ addAttrs(el, [{
1909
+ name: ':' + classLikeAttrName,
1910
+ value: `[${replacements.join(',')}].join(' ')`
1911
+ }])
1912
+ }
1913
+ })
1914
+ }
1875
1915
  }
1876
1916
 
1877
1917
  function processScoped (el, options) {
@@ -1909,7 +1949,7 @@ function processAliStyleClassHack (el, options, root) {
1909
1949
  processor = ({ name, value, typeName }) => {
1910
1950
  let sep = name === 'style' ? ';' : ' '
1911
1951
  value = value ? `{{${typeName}||''}}${sep}${value}` : `{{${typeName}||''}}`
1912
- return [ name, value ]
1952
+ return [name, value]
1913
1953
  }
1914
1954
  }
1915
1955
  // 非上述两种不处理
@@ -1931,6 +1971,7 @@ function processAliStyleClassHack (el, options, root) {
1931
1971
  }
1932
1972
  })
1933
1973
  }
1974
+
1934
1975
  // 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
1935
1976
  function getVirtualHostRoot (options, meta) {
1936
1977
  if (options.isComponent) {
@@ -39,7 +39,6 @@ module.exports = function (script, options, callback) {
39
39
  const genericsInfo = options.genericsInfo
40
40
  const componentGenerics = options.componentGenerics
41
41
  const forceDisableBuiltInLoader = options.forceDisableBuiltInLoader
42
- const webRouteMode = options.webRouteMode
43
42
 
44
43
  const emitWarning = (msg) => {
45
44
  loaderContext.emitWarning(
@@ -110,12 +109,6 @@ module.exports = function (script, options, callback) {
110
109
  import Vue from 'vue'
111
110
  import VueRouter from 'vue-router'
112
111
  Vue.use(VueRouter)
113
- import BScroll from '@better-scroll/core'
114
- import PullDown from '@better-scroll/pull-down'
115
- import ObserveDOM from '@better-scroll/observe-dom'
116
- BScroll.use(ObserveDOM)
117
- BScroll.use(PullDown)
118
- global.BScroll = BScroll
119
112
  global.getApp = function(){}
120
113
  global.getCurrentPages = function(){
121
114
  if(!global.__mpxRouter) return []
@@ -255,8 +248,7 @@ module.exports = function (script, options, callback) {
255
248
  ${JSON.stringify(tabBarMap)},
256
249
  ${JSON.stringify(componentGenerics)},
257
250
  ${JSON.stringify(genericsInfo)},
258
- getWxsMixin(wxsModules),
259
- ${JSON.stringify(webRouteMode)}`
251
+ getWxsMixin(wxsModules)`
260
252
 
261
253
  if (ctorType === 'app') {
262
254
  content += `,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.6.107",
3
+ "version": "2.6.111",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -81,5 +81,5 @@
81
81
  "@types/babel-traverse": "^6.25.4",
82
82
  "@types/babel-types": "^7.0.4"
83
83
  },
84
- "gitHead": "c5821595c58c2908d56de41e68f1462b949bf646"
84
+ "gitHead": "274251aa90b9c2b22574ad31fe85093c4dedbb27"
85
85
  }