@mpxjs/webpack-plugin 2.6.105 → 2.6.110

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
@@ -23,9 +23,9 @@ module.exports = function (content) {
23
23
  const mpx = mainCompilation.__mpx__
24
24
 
25
25
  const pagesMap = mpx.pagesMap
26
+ const getOutputPath = mpx.getOutputPath
26
27
 
27
28
  const extract = mpx.extract
28
- const pathHash = mpx.pathHash
29
29
  const extractedMap = mpx.extractedMap
30
30
  const mode = mpx.mode
31
31
  const typeExtMap = config[mode].typeExtMap
@@ -50,8 +50,7 @@ module.exports = function (content) {
50
50
  if (filename) {
51
51
  return filename + typeExtMap[type]
52
52
  } else {
53
- const resourceName = path.parse(resourcePath).name
54
- const outputPath = path.join(type, resourceName + pathHash(resourcePath) + typeExtMap[type])
53
+ const outputPath = getOutputPath(resourcePath, type, { ext: typeExtMap[type] })
55
54
  return mpx.getPackageInfo({
56
55
  resource: resourceRaw,
57
56
  outputPath,
package/lib/index.js CHANGED
@@ -124,6 +124,7 @@ class MpxWebpackPlugin {
124
124
  options.forceUsePageCtor = options.forceUsePageCtor || false
125
125
  options.postcssInlineConfig = options.postcssInlineConfig || {}
126
126
  options.transRpxRules = options.transRpxRules || null
127
+ options.webConfig = options.webConfig || {}
127
128
  options.auditResource = options.auditResource || false
128
129
  options.decodeHTMLText = options.decodeHTMLText || false
129
130
  options.nativeOptions = Object.assign({
@@ -142,6 +143,7 @@ class MpxWebpackPlugin {
142
143
  options.fileConditionRules = options.fileConditionRules || {
143
144
  include: () => true
144
145
  }
146
+ options.customOutputPath = options.customOutputPath || null
145
147
  this.options = options
146
148
  }
147
149
 
@@ -361,10 +363,12 @@ class MpxWebpackPlugin {
361
363
  compilation.errors.push(e)
362
364
  }
363
365
  })
364
- if (packageRoot) {
365
- module.request = addQuery(module.request, { packageRoot })
366
- module.resource = addQuery(module.resource, { packageRoot })
367
- }
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)
368
372
  }
369
373
  }
370
374
 
@@ -411,6 +415,7 @@ class MpxWebpackPlugin {
411
415
  // 当前机制下分包处理队列在app.json的json-compiler中进行,由于addEntry回调特性,无法保障app.js中引用的模块都被标记为主包,故重写processModuleDependencies获取app.js及其所有依赖处理完成的时机,在这之后再执行分包处理队列
412
416
  appScriptRawRequest: '',
413
417
  appScriptPromise: null,
418
+ appScriptPromiseResolve: null,
414
419
  // 记录entry依赖关系,用于体积分析
415
420
  entryNodesMap: {},
416
421
  // 记录entryModule与entryNode的对应关系,用于体积分析
@@ -438,6 +443,7 @@ class MpxWebpackPlugin {
438
443
  autoScopeRules: this.options.autoScopeRules,
439
444
  autoVirtualHostRules: this.options.autoVirtualHostRules,
440
445
  transRpxRules: this.options.transRpxRules,
446
+ webConfig: this.options.webConfig,
441
447
  postcssInlineConfig: this.options.postcssInlineConfig,
442
448
  decodeHTMLText: this.options.decodeHTMLText,
443
449
  // native文件专用相关配置
@@ -484,6 +490,15 @@ class MpxWebpackPlugin {
484
490
  }
485
491
  return hash(hashPath)
486
492
  },
493
+ getOutputPath: (resourcePath, type, { ext = '', conflictPath = '' } = {}) => {
494
+ const name = path.parse(resourcePath).name
495
+ const hash = mpx.pathHash(resourcePath)
496
+ const customOutputPath = this.options.customOutputPath
497
+ if (conflictPath) return conflictPath.replace(/(\.[^\\/]+)?$/, match => hash + match)
498
+ if (typeof customOutputPath === 'function') return customOutputPath(type, name, hash, ext)
499
+ if (type === 'component' || type === 'page') return path.join(type + 's', name + hash, 'index' + ext)
500
+ return path.join(type, name + hash + ext)
501
+ },
487
502
  extract: (content, file, index, sideEffects) => {
488
503
  index = index === -1 ? 0 : index
489
504
  additionalAssets[file] = additionalAssets[file] || []
@@ -549,6 +564,13 @@ class MpxWebpackPlugin {
549
564
  if (currentResourceMap[resourcePath] === outputPath) {
550
565
  alreadyOutputed = true
551
566
  } else {
567
+ for (let key in currentResourceMap) {
568
+ if (currentResourceMap[key] === outputPath && key !== resourcePath) {
569
+ outputPath = toPosix(path.join(packageRoot, mpx.getOutputPath(resourcePath, resourceType, { conflictPath: outputPath })))
570
+ warn && warn(new Error(`Current ${resourceType} [${resourcePath}] is registered with a conflict outputPath [${currentResourceMap[key]}] which is already existed in system, will be renamed with [${outputPath}], use ?resolve to get the real outputPath!`))
571
+ break
572
+ }
573
+ }
552
574
  currentResourceMap[resourcePath] = outputPath
553
575
  }
554
576
  } else if (!currentResourceMap[resourcePath]) {
@@ -571,12 +593,10 @@ class MpxWebpackPlugin {
571
593
  if (module.rawRequest === mpx.appScriptRawRequest) {
572
594
  // 避免模块request重名,只对第一次匹配到的模块进行代理
573
595
  mpx.appScriptRawRequest = ''
574
- mpx.appScriptPromise = new Promise((resolve) => {
575
- proxyedCallback = (err) => {
576
- resolve()
577
- return callback(err)
578
- }
579
- })
596
+ proxyedCallback = (err) => {
597
+ mpx.appScriptPromiseResolve()
598
+ return callback(err)
599
+ }
580
600
  }
581
601
  return rawProcessModuleDependencies.apply(compilation, [module, proxyedCallback])
582
602
  }
@@ -26,6 +26,7 @@ module.exports = function (raw = '{}') {
26
26
  const options = loaderUtils.getOptions(this) || {}
27
27
  const mainCompilation = getMainCompilation(this._compilation)
28
28
  const mpx = mainCompilation.__mpx__
29
+ const getOutputPath = mpx.getOutputPath
29
30
 
30
31
  const emitWarning = (msg) => {
31
32
  this.emitWarning(
@@ -297,8 +298,7 @@ module.exports = function (raw = '{}') {
297
298
  let relativePath = path.relative(root, resourceName)
298
299
  outputPath = path.join('components', name + pathHash(root), relativePath)
299
300
  } else {
300
- let componentName = parsed.name
301
- outputPath = path.join('components', componentName + pathHash(resourcePath), componentName)
301
+ outputPath = getOutputPath(resourcePath, 'component')
302
302
  }
303
303
  }
304
304
  const { packageRoot, outputPath: componentPath, alreadyOutputed } = mpx.getPackageInfo({
@@ -515,10 +515,10 @@ module.exports = function (raw = '{}') {
515
515
  callback()
516
516
  }
517
517
 
518
- const getPageName = (resourcePath, ext) => {
519
- const baseName = path.basename(resourcePath, ext)
520
- return path.join('pages', baseName + pathHash(resourcePath), baseName)
521
- }
518
+ // const getPageName = (resourcePath, ext) => {
519
+ // const baseName = path.basename(resourcePath, ext)
520
+ // return path.join('pages', baseName + pathHash(resourcePath), baseName)
521
+ // }
522
522
 
523
523
  const processPages = (pages, srcRoot = '', tarRoot = '', context, callback) => {
524
524
  if (pages) {
@@ -552,18 +552,18 @@ module.exports = function (raw = '{}') {
552
552
  const relative = path.relative(context, resourcePath)
553
553
  if (/^\./.test(relative)) {
554
554
  // 如果当前page不存在于context中,对其进行重命名
555
- pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
555
+ pageName = getOutputPath(resourcePath, 'page')
556
556
  emitWarning(`Current page [${resourcePath}] is not in current pages directory [${context}], the page path will be replaced with [${pageName}], use ?resolve to get the page path and navigate to it!`)
557
557
  } else {
558
558
  pageName = toPosix(path.join(tarRoot, /^(.*?)(\.[^.]*)?$/.exec(relative)[1]))
559
559
  // 如果当前page与已有page存在命名冲突,也进行重命名
560
- for (let key in pagesMap) {
561
- if (pagesMap[key] === pageName && key !== resourcePath) {
562
- const pageNameRaw = pageName
563
- pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
564
- emitWarning(`Current page [${resourcePath}] is registered with a conflict page path [${pageNameRaw}] which is already existed in system, the page path will be replaced with [${pageName}], use ?resolve to get the page path and navigate to it!`)
565
- break
566
- }
560
+ }
561
+ for (let key in pagesMap) {
562
+ if (pagesMap[key] === pageName && key !== resourcePath) {
563
+ const pageNameRaw = pageName
564
+ pageName = getOutputPath(resourcePath, 'page', { conflictPath: pageNameRaw })
565
+ emitWarning(`Current page [${resourcePath}] is registered with a conflict page path [${pageNameRaw}] which is already existed in system, the page path will be replaced with [${pageName}], use ?resolve to get the page path and navigate to it!`)
566
+ break
567
567
  }
568
568
  }
569
569
  }
package/lib/loader.js CHANGED
@@ -273,9 +273,8 @@ module.exports = function (content) {
273
273
  if (!isProduction) {
274
274
  globalInjectCode += `global.currentResource = ${JSON.stringify(filePath)}\n`
275
275
  }
276
- if (ctorType === 'app' && i18n && !mpx.forceDisableInject) {
277
- globalInjectCode += `global.i18n = ${JSON.stringify({ locale: i18n.locale, version: 0 })}\n`
278
276
 
277
+ if (i18n && (ctorType === 'app' || (ctorType === 'page' && queryObj.isIndependent)) && !mpx.forceDisableInject) {
279
278
  const i18nMethodsVar = 'i18nMethods'
280
279
  const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
281
280
  const i18nWxsLoaderPath = normalize.lib('wxs/wxs-i18n-loader.js')
@@ -293,7 +292,10 @@ module.exports = function (content) {
293
292
  })
294
293
  this._module.addVariable(i18nMethodsVar, expression, deps)
295
294
 
296
- 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`
297
299
  }
298
300
  // 注入构造函数
299
301
  let ctor = 'App'
@@ -329,7 +331,12 @@ module.exports = function (content) {
329
331
  }
330
332
  if (scriptRequestString) {
331
333
  output += 'export * from ' + scriptRequestString + '\n\n'
332
- 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
+ }
333
340
  }
334
341
  } else {
335
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
  }
@@ -54,6 +54,7 @@ module.exports = function (source) {
54
54
  const context = this.context
55
55
  const packageName = 'main'
56
56
  const pagesMap = mpx.pagesMap
57
+ const getOutputPath = mpx.getOutputPath
57
58
  const componentsMap = mpx.componentsMap[packageName]
58
59
  const getEntryNode = mpx.getEntryNode
59
60
  const resolveMode = mpx.resolveMode
@@ -191,8 +192,7 @@ module.exports = function (source) {
191
192
  let relativePath = path.relative(root, resourceName)
192
193
  outputPath = path.join('components', name + pathHash(root), relativePath)
193
194
  } else {
194
- let componentName = parsed.name
195
- outputPath = path.join('components', componentName + pathHash(resourcePath), componentName)
195
+ outputPath = getOutputPath(resourcePath, 'component')
196
196
  }
197
197
  const componentPath = toPosix(outputPath)
198
198
  pluginEntry.publicComponents[name] = componentPath
@@ -1,5 +1,6 @@
1
1
  <script>
2
2
  import { inBrowser } from '../../../utils/env'
3
+
3
4
  function isDef (v) {
4
5
  return v !== undefined && v !== null
5
6
  }
@@ -30,7 +31,7 @@
30
31
 
31
32
  function getVnodeKey (vnode) {
32
33
  if (vnode && vnode.componentOptions) {
33
- return vnode.key || vnode.componentOptions.Ctor.cid + (vnode.componentOptions.tag ? ('::' + (vnode.componentOptions.tag)) : '')
34
+ return vnode.componentOptions.Ctor.cid + (vnode.componentOptions.tag ? ('::' + (vnode.componentOptions.tag)) : '')
34
35
  }
35
36
  }
36
37
 
@@ -73,6 +74,8 @@
73
74
  const current = stack[i - 1]
74
75
  if (current.vnode && current.vnodeKey === vnodeKey && current.vnode.componentInstance) {
75
76
  vnode.componentInstance = current.vnode.componentInstance
77
+ // 避免组件实例复用但是vnode.key不一致带来的bad case
78
+ vnode.key = current.vnode.key
76
79
  break
77
80
  }
78
81
  }
@@ -15,7 +15,7 @@
15
15
  'mpx-tab-bar': tabBarPagesMap['mpx-tab-bar']
16
16
  }
17
17
  tabBar.list.forEach(({ pagePath }) => {
18
- const name = pagePath.replace('/', '-')
18
+ const name = pagePath.replace(/\//g, '-')
19
19
  const page = tabBarPagesMap[pagePath]
20
20
  if (page) {
21
21
  components[name] = page
@@ -39,7 +39,7 @@
39
39
  currentComponent () {
40
40
  const index = this.currentIndex
41
41
  const tabItem = tabBar.list[index]
42
- return tabItem.pagePath.replace('/', '-')
42
+ return tabItem.pagePath.replace(/\//g, '-')
43
43
  }
44
44
  },
45
45
  watch: {
@@ -25,23 +25,6 @@ export default function processOption (
25
25
  }
26
26
  }
27
27
 
28
- // 注册v-ex-classes自定义指令处理externalClasses
29
- Vue.directive('ex-classes', (el, binding, vnode) => {
30
- const context = vnode.context
31
- if (context) {
32
- const externalClasses = context.$options.externalClasses || []
33
- const classList = el.classList
34
- binding.value.forEach((className) => {
35
- const actualExternalClassNames = context.$attrs[className]
36
- if (externalClasses.indexOf(className) !== -1 && actualExternalClassNames) {
37
- classList.remove(className)
38
- actualExternalClassNames.split(/\s+/).forEach((actualExternalClassName) => {
39
- if (actualExternalClassName) classList.add(actualExternalClassName)
40
- })
41
- }
42
- })
43
- }
44
- })
45
28
  Vue.directive('animation', (el, binding) => {
46
29
  const newActions = binding && binding.value && binding.value.actions
47
30
  if (el.actions === newActions) {
@@ -121,7 +104,9 @@ export default function processOption (
121
104
  redirect: '/' + firstPage
122
105
  })
123
106
  }
107
+ const webRouteConfig = global.__mpx.config.webRouteConfig
124
108
  global.__mpxRouter = option.router = new VueRouter({
109
+ ...webRouteConfig,
125
110
  routes: routes
126
111
  })
127
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 }) => {
@@ -1,7 +1,7 @@
1
- const babylon = require('babylon')
2
- const traverse = require('babel-traverse').default
3
- const t = require('babel-types')
4
- const generate = require('babel-generator').default
1
+ const babylon = require('@babel/parser')
2
+ const traverse = require('@babel/traverse').default
3
+ const t = require('@babel/types')
4
+ const generate = require('@babel/generator').default
5
5
 
6
6
  let names = 'Infinity,undefined,NaN,isFinite,isNaN,' +
7
7
  'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
@@ -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) {
@@ -1,6 +1,6 @@
1
- const babylon = require('babylon')
2
- const t = require('babel-types')
3
- const generate = require('babel-generator').default
1
+ const babylon = require('@babel/parser')
2
+ const t = require('@babel/types')
3
+ const generate = require('@babel/generator').default
4
4
  const dash2hump = require('../utils/hump-dash').dash2hump
5
5
 
6
6
  module.exports = function transDynamicClassExpr (expr) {
@@ -17,6 +17,7 @@ module.exports = function () {
17
17
  const assetsInfo = mpx.assetsInfo
18
18
  const mode = mpx.mode
19
19
  const wxsMap = mpx.wxsMap
20
+ const getOutputPath = mpx.getOutputPath
20
21
  const rootName = mainCompilation._preparedEntrypoints[0].name
21
22
  let { resourcePath, queryObj } = parseRequest(this.resource)
22
23
  const { resourcePath: issuerResourcePath, queryObj: issuerQueryObj } = parseRequest(queryObj.issuerResource || this._module.issuer.resource)
@@ -36,9 +37,9 @@ module.exports = function () {
36
37
  if (wxsModule) {
37
38
  resourcePath = `${resourcePath}~${wxsModule}`
38
39
  }
39
-
40
- const name = path.parse(resourcePath).name + mpx.pathHash(resourcePath)
41
- let filename = path.join(/^\.([^.]+)/.exec(config[mode].wxs.ext)[1], `${name}${config[mode].wxs.ext}`)
40
+ const packageRoot = queryObj.packageRoot || ''
41
+ const ext = config[mode].wxs.ext
42
+ let filename = toPosix(path.join(packageRoot, getOutputPath(resourcePath, ext.slice(1), { ext })))
42
43
 
43
44
  filename = mpx.getPackageInfo({
44
45
  resource: this.resource,
@@ -1,7 +1,7 @@
1
- const babylon = require('babylon')
2
- const traverse = require('babel-traverse').default
3
- const t = require('babel-types')
4
- const generate = require('babel-generator').default
1
+ const babylon = require('@babel/parser')
2
+ const traverse = require('@babel/traverse').default
3
+ const t = require('@babel/types')
4
+ const generate = require('@babel/generator').default
5
5
  const getMainCompilation = require('../utils/get-main-compilation')
6
6
  const parseRequest = require('../utils/parse-request')
7
7
  const isEmptyObject = require('../utils/is-empty-object')
@@ -3,37 +3,37 @@
3
3
  Author Tobias Koppers @sokra
4
4
  Modified by @hiyuki
5
5
  */
6
- var formatCodeFrame = require('babel-code-frame')
7
- var Tokenizer = require('css-selector-tokenizer')
8
- var postcss = require('postcss')
9
- var loaderUtils = require('loader-utils')
10
- var assign = require('object-assign')
11
- var getLocalIdent = require('./getLocalIdent')
6
+ const formatCodeFrame = require('@babel/code-frame')
7
+ const Tokenizer = require('css-selector-tokenizer')
8
+ const postcss = require('postcss')
9
+ const loaderUtils = require('loader-utils')
10
+ const assign = require('object-assign')
11
+ const getLocalIdent = require('./getLocalIdent')
12
12
 
13
- var icssUtils = require('icss-utils')
14
- var localByDefault = require('postcss-modules-local-by-default')
15
- var extractImports = require('postcss-modules-extract-imports')
16
- var modulesScope = require('postcss-modules-scope')
17
- var modulesValues = require('postcss-modules-values')
18
- var valueParser = require('postcss-value-parser')
19
- var isUrlRequest = require('../utils/is-url-request')
13
+ const icssUtils = require('icss-utils')
14
+ const localByDefault = require('postcss-modules-local-by-default')
15
+ const extractImports = require('postcss-modules-extract-imports')
16
+ const modulesScope = require('postcss-modules-scope')
17
+ const modulesValues = require('postcss-modules-values')
18
+ const valueParser = require('postcss-value-parser')
19
+ const isUrlRequest = require('../utils/is-url-request')
20
20
 
21
- var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
21
+ const parserPlugin = postcss.plugin('css-loader-parser', function (options) {
22
22
  return function (css) {
23
- var imports = {}
24
- var exports = {}
25
- var importItems = []
26
- var urlItems = []
23
+ const imports = {}
24
+ let exports = {}
25
+ const importItems = []
26
+ const urlItems = []
27
27
 
28
28
  function replaceImportsInString (str) {
29
29
  if (options.import) {
30
- var tokens = valueParser(str)
30
+ const tokens = valueParser(str)
31
31
  tokens.walk(function (node) {
32
32
  if (node.type !== 'word') {
33
33
  return
34
34
  }
35
- var token = node.value
36
- var importIndex = imports['$' + token]
35
+ const token = node.value
36
+ const importIndex = imports['$' + token]
37
37
  if (typeof importIndex === 'number') {
38
38
  node.value = '___CSS_LOADER_IMPORT___' + importIndex + '___'
39
39
  }
@@ -45,8 +45,8 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
45
45
 
46
46
  if (options.import) {
47
47
  css.walkAtRules(/^import$/i, function (rule) {
48
- var values = Tokenizer.parseValues(rule.params)
49
- var url = values.nodes[0].nodes[0]
48
+ const values = Tokenizer.parseValues(rule.params)
49
+ let url = values.nodes[0].nodes[0]
50
50
  if (url && url.type === 'url') {
51
51
  url = url.url
52
52
  } else if (url && url.type === 'string') {
@@ -56,7 +56,7 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
56
56
  return
57
57
  }
58
58
  values.nodes[0].nodes.shift()
59
- var mediaQuery = Tokenizer.stringifyValues(values)
59
+ const mediaQuery = Tokenizer.stringifyValues(values)
60
60
 
61
61
  if (isUrlRequest(url, options.root)) {
62
62
  url = loaderUtils.urlToRequest(url, options.root)
@@ -70,10 +70,10 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
70
70
  })
71
71
  }
72
72
 
73
- var icss = icssUtils.extractICSS(css)
73
+ const icss = icssUtils.extractICSS(css)
74
74
  exports = icss.icssExports
75
75
  Object.keys(icss.icssImports).forEach(function (key) {
76
- var url = loaderUtils.parseString(key)
76
+ const url = loaderUtils.parseString(key)
77
77
  Object.keys(icss.icssImports[key]).forEach(function (prop) {
78
78
  imports['$' + prop] = importItems.length
79
79
  importItems.push({
@@ -101,7 +101,7 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
101
101
  item.nodes.forEach(processNode)
102
102
  break
103
103
  case 'item':
104
- var importIndex = imports['$' + item.name]
104
+ const importIndex = imports['$' + item.name]
105
105
  if (typeof importIndex === 'number') {
106
106
  item.name = '___CSS_LOADER_IMPORT___' + importIndex + '___'
107
107
  }
@@ -112,7 +112,7 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
112
112
  item.stringType = ''
113
113
  delete item.innerSpacingBefore
114
114
  delete item.innerSpacingAfter
115
- var url = item.url
115
+ const url = item.url
116
116
  item.url = '___CSS_LOADER_URL___' + urlItems.length + '___'
117
117
  urlItems.push({
118
118
  url: url
@@ -123,7 +123,7 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
123
123
  }
124
124
 
125
125
  css.walkDecls(function (decl) {
126
- var values = Tokenizer.parseValues(decl.value)
126
+ const values = Tokenizer.parseValues(decl.value)
127
127
  values.nodes.forEach(function (value) {
128
128
  value.nodes.forEach(processNode)
129
129
  })
@@ -142,17 +142,17 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
142
142
  })
143
143
 
144
144
  module.exports = function processCss (inputSource, inputMap, options, callback) {
145
- var query = options.query
146
- var root = query.root && query.root.length > 0 ? query.root.replace(/\/$/, '') : query.root
147
- var context = query.context
148
- var localIdentName = query.localIdentName || '[hash:base64]'
149
- var localIdentRegExp = query.localIdentRegExp
150
- var forceMinimize = query.minimize
151
- var minimize = typeof forceMinimize !== 'undefined' ? !!forceMinimize : options.minimize
145
+ const query = options.query
146
+ const root = query.root && query.root.length > 0 ? query.root.replace(/\/$/, '') : query.root
147
+ const context = query.context
148
+ const localIdentName = query.localIdentName || '[hash:base64]'
149
+ const localIdentRegExp = query.localIdentRegExp
150
+ const forceMinimize = query.minimize
151
+ const minimize = typeof forceMinimize !== 'undefined' ? !!forceMinimize : options.minimize
152
152
 
153
- var customGetLocalIdent = query.getLocalIdent || getLocalIdent
153
+ const customGetLocalIdent = query.getLocalIdent || getLocalIdent
154
154
 
155
- var parserOptions = {
155
+ const parserOptions = {
156
156
  root: root,
157
157
  mode: options.mode,
158
158
  url: query.url !== false,
@@ -160,7 +160,7 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
160
160
  resolve: options.resolve
161
161
  }
162
162
 
163
- var pipeline = postcss([
163
+ const pipeline = postcss([
164
164
  modulesValues,
165
165
  localByDefault({
166
166
  mode: options.mode,
@@ -192,8 +192,8 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
192
192
  ])
193
193
 
194
194
  if (minimize) {
195
- var cssnano = require('cssnano')
196
- var minimizeOptions = assign({}, query.minimize);
195
+ const cssnano = require('cssnano')
196
+ const minimizeOptions = assign({}, query.minimize);
197
197
  ['zindex', 'normalizeUrl', 'discardUnused', 'mergeIdents', 'reduceIdents', 'autoprefixer', 'svgo'].forEach(function (name) {
198
198
  if (typeof minimizeOptions[name] === 'undefined') {
199
199
  minimizeOptions[name] = false
@@ -226,7 +226,7 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
226
226
  })
227
227
  }).catch(function (err) {
228
228
  if (err.name === 'CssSyntaxError') {
229
- var wrappedError = new CSSLoaderError(
229
+ const wrappedError = new CSSLoaderError(
230
230
  'Syntax Error',
231
231
  err.reason,
232
232
  err.line != null && err.column != null
@@ -242,7 +242,7 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
242
242
  }
243
243
 
244
244
  function formatMessage (message, loc, source) {
245
- var formatted = message
245
+ let formatted = message
246
246
  if (loc) {
247
247
  formatted = formatted +
248
248
  ' (' + loc.line + ':' + loc.column + ')'
@@ -260,7 +260,7 @@ function CSSLoaderError (name, message, loc, source, error) {
260
260
  this.name = name
261
261
  this.error = error
262
262
  this.message = formatMessage(message, loc, source)
263
- this.hideStack = true
263
+ this.message = formatMessage(message, loc, source)
264
264
  }
265
265
 
266
266
  CSSLoaderError.prototype = Object.create(Error.prototype)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.6.105",
3
+ "version": "2.6.110",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -15,6 +15,11 @@
15
15
  "lib"
16
16
  ],
17
17
  "dependencies": {
18
+ "@babel/code-frame": "^7.16.0",
19
+ "@babel/generator": "^7.16.0",
20
+ "@babel/parser": "^7.16.2",
21
+ "@babel/traverse": "^7.16.0",
22
+ "@babel/types": "^7.16.0",
18
23
  "@better-scroll/core": "^2.2.1",
19
24
  "@better-scroll/movable": "^2.2.1",
20
25
  "@better-scroll/observe-dom": "^2.2.1",
@@ -24,11 +29,6 @@
24
29
  "@better-scroll/zoom": "^2.2.1",
25
30
  "acorn-walk": "^7.2.0",
26
31
  "async": "^2.6.0",
27
- "babel-code-frame": "^6.26.0",
28
- "babel-generator": "^6.26.1",
29
- "babel-traverse": "^6.26.0",
30
- "babel-types": "^6.26.0",
31
- "babylon": "^6.18.0",
32
32
  "consolidate": "^0.15.1",
33
33
  "css": "^2.2.1",
34
34
  "css-selector-tokenizer": "^0.7.0",
@@ -81,5 +81,5 @@
81
81
  "@types/babel-traverse": "^6.25.4",
82
82
  "@types/babel-types": "^7.0.4"
83
83
  },
84
- "gitHead": "499f344f87d78f90acdf7110182a71f96f3bf0de"
84
+ "gitHead": "a772b52decbf4a3bdc3b5b608a18327bce453b6c"
85
85
  }