@mpxjs/webpack-plugin 2.7.3 → 2.7.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.
@@ -117,8 +117,11 @@ class DynamicEntryDependency extends NullDependency {
117
117
 
118
118
  DynamicEntryDependency.Template = class DynamicEntryDependencyTemplate {
119
119
  apply (dep, source) {
120
- const { resultPath, range, key } = dep
121
- if (resultPath) {
120
+ const { resultPath, range, key, outputPath } = dep
121
+ if (outputPath === 'custom-tab-bar/index') {
122
+ // replace with true for custom-tab-bar
123
+ source.replace(range[0], range[1] - 1, 'true')
124
+ } else if (resultPath) {
122
125
  source.replace(range[0], range[1] - 1, JSON.stringify(resultPath))
123
126
  } else {
124
127
  const replaceRange = `mpx_replace_path_${key}`
package/lib/extractor.js CHANGED
@@ -16,7 +16,7 @@ module.exports.pitch = async function (remainingRequest) {
16
16
  const type = queryObj.type
17
17
  const index = queryObj.index || 0
18
18
  const isStatic = queryObj.isStatic
19
- const issuerFile = queryObj.issuerFile
19
+ const issuerResource = queryObj.issuerResource
20
20
  const fromImport = queryObj.fromImport
21
21
  const needBabel = queryObj.needBabel
22
22
 
@@ -82,7 +82,8 @@ module.exports.pitch = async function (remainingRequest) {
82
82
  // styles为static就两种情况,一种是.mpx中使用src引用样式,第二种为css-loader中处理@import
83
83
  // 为了支持持久化缓存,.mpx中使用src引用样式对issueFile asset产生的副作用迁移到ExtractDependency中处理
84
84
  case 'styles':
85
- if (issuerFile) {
85
+ if (issuerResource) {
86
+ const issuerFile = mpx.getExtractedFile(issuerResource)
86
87
  let relativePath = toPosix(path.relative(path.dirname(issuerFile), file))
87
88
  relativePath = fixRelative(relativePath, mode)
88
89
  if (fromImport) {
package/lib/index.js CHANGED
@@ -279,7 +279,7 @@ class MpxWebpackPlugin {
279
279
 
280
280
  const addModePlugin = new AddModePlugin('before-file', this.options.mode, this.options.fileConditionRules, 'file')
281
281
  const addEnvPlugin = new AddEnvPlugin('before-file', this.options.env, this.options.fileConditionRules, 'file')
282
- const packageEntryPlugin = new PackageEntryPlugin('before-described-relative', this.options.miniNpmPackages, 'resolve')
282
+ const packageEntryPlugin = new PackageEntryPlugin('before-file', this.options.miniNpmPackages, 'file')
283
283
  if (Array.isArray(compiler.options.resolve.plugins)) {
284
284
  compiler.options.resolve.plugins.push(addModePlugin)
285
285
  } else {
@@ -474,11 +474,12 @@ module.exports = function (content) {
474
474
 
475
475
  const processCustomTabBar = (tabBar, context, callback) => {
476
476
  if (tabBar && tabBar.custom) {
477
- processComponent('./custom-tab-bar/index', context, { outputPath: 'custom-tab-bar/index' }, (err) => {
477
+ processComponent('./custom-tab-bar/index', context, { outputPath: 'custom-tab-bar/index' }, (err, entry) => {
478
478
  if (err === RESOLVE_IGNORED_ERR) {
479
479
  delete tabBar.custom
480
480
  return callback()
481
481
  }
482
+ tabBar.custom = entry // hack for javascript parser call hook.
482
483
  callback(err)
483
484
  })
484
485
  } else {
package/lib/loader.js CHANGED
@@ -290,7 +290,7 @@ module.exports = function (content) {
290
290
  ...style.src ? {
291
291
  ...queryObj,
292
292
  isStatic: true,
293
- issuerFile: mpx.getExtractedFile(addQuery(this.resource, { type: 'styles' }, true))
293
+ issuerResource: addQuery(this.resource, { type: 'styles' }, true)
294
294
  } : null,
295
295
  moduleId,
296
296
  scoped
@@ -1,55 +1,42 @@
1
1
  const path = require('path')
2
- /**
3
- * @desc 获取小程序npm包资源入口目录
4
- */
5
- const getEntry = (name, miniprogram) => {
6
- return path.join(name, miniprogram)
7
- }
2
+ const toPosix = require('../utils/to-posix')
8
3
 
9
4
  module.exports = class PackageEntryPlugin {
10
- constructor (source, miniNpmPackage, target) {
5
+ constructor (source, miniNpmPackages, target) {
11
6
  this.source = source
12
7
  this.target = target
13
- this.miniNpmPackage = miniNpmPackage
8
+ this.miniNpmPackages = miniNpmPackages
14
9
  }
15
10
 
16
11
  /**
17
12
  * 判断是否需要更改innerRequest
18
13
  * 小程序发布npm包约束: package.json配置miniprogram 或默认 miniprogram_dist目录
19
- * 0. 前提: request中含有package.json中name字段
20
14
  * 1. package.json中配置了miniprogram, 且request中不含miniprogram,尝试拼接
21
- * 2. 用户配置miniNpmPackage说明是小程序npm包,如果package.json中没配置miniprogram字段,则尝试拼接默认miniprogram_dist目录
15
+ * 2. 用户配置miniNpmPackages说明是小程序npm包,如果package.json中没配置miniprogram字段,则尝试拼接默认miniprogram_dist目录
22
16
  */
23
17
  apply (resolver) {
24
18
  const target = resolver.ensureHook(this.target)
25
19
  resolver.getHook(this.source).tapAsync('PackagePlugin', (request, resolveContext, callback) => {
26
- const innerRequest = request.request || request.path
27
- if (!innerRequest || request.miniprogram) return callback()
20
+ if (request.miniprogram) return callback()
21
+ let { path: resourcePath, descriptionFileData, descriptionFileRoot } = request
22
+ if (request.miniprogram || !descriptionFileData) return callback()
23
+
24
+ let { name, miniprogram } = descriptionFileData
25
+ if (!miniprogram && this.miniNpmPackages.includes(name)) miniprogram = 'miniprogram_dist'
26
+ if (!miniprogram) return callback()
27
+
28
+ let relativePath = path.relative(descriptionFileRoot, resourcePath)
29
+ if (relativePath.startsWith(miniprogram)) return callback()
30
+
31
+ relativePath = path.join(miniprogram, relativePath)
28
32
 
29
- const descriptionFileData = request.descriptionFileData || {}
30
- const { name = '', miniprogram } = descriptionFileData
31
- let newEntry = ''
32
- // request.path和系统环境有关:windows和linux
33
- let normalizedName = path.normalize(name)
34
- if (innerRequest.indexOf(normalizedName) === -1) {
35
- return callback()
36
- }
37
- if (miniprogram) {
38
- newEntry = getEntry(normalizedName, miniprogram)
39
- } else if (this.miniNpmPackage.includes(name)) {
40
- newEntry = getEntry(normalizedName, 'miniprogram_dist')
41
- }
33
+ const obj = Object.assign({}, request, {
34
+ path: path.join(descriptionFileRoot, relativePath),
35
+ relativePath: './' + toPosix(relativePath),
36
+ miniprogram: true
37
+ })
42
38
 
43
- if (newEntry) {
44
- const newRequest = innerRequest.replace(normalizedName, newEntry)
45
- const obj = Object.assign({}, request, {
46
- request: newRequest,
47
- miniprogram: true
48
- })
49
- resolver.doResolve(target, obj, `change request ${innerRequest} to :` + newRequest, resolveContext, callback)
50
- } else {
51
- callback()
52
- }
39
+ resolver.doResolve(target, obj, 'add miniprogram dist: ' + miniprogram, resolveContext, callback)
53
40
  })
54
41
  }
55
42
  }
@@ -85,6 +85,10 @@
85
85
  animation: {
86
86
  type: Boolean,
87
87
  default: true
88
+ },
89
+ speed: {
90
+ type: Number,
91
+ default: 1000
88
92
  }
89
93
  },
90
94
  watch: {
@@ -96,7 +100,7 @@
96
100
  if (newVal < this.bs.maxScrollX) {
97
101
  newVal = this.bs.maxScrollX
98
102
  }
99
- this.bs.scrollTo(newVal, this.bs.y)
103
+ this.bs.scrollTo(newVal, this.bs.y, this.speed)
100
104
  },
101
105
  y (newVal) {
102
106
  this.source = ''
@@ -106,7 +110,7 @@
106
110
  if (newVal < this.bs.maxScrollY) {
107
111
  newVal = this.bs.maxScrollY
108
112
  }
109
- this.bs.scrollTo(this.bs.x, newVal)
113
+ this.bs.scrollTo(this.bs.x, newVal, this.speed)
110
114
  },
111
115
  scaleValue (newVal) {
112
116
  this.isZooming = true
@@ -1,29 +1,34 @@
1
1
  const babylon = require('@babel/parser')
2
2
  const t = require('@babel/types')
3
+ const traverse = require('@babel/traverse').default
3
4
  const generate = require('@babel/generator').default
4
5
 
5
6
  module.exports = function transDynamicClassExpr (expr, { error } = {}) {
6
7
  try {
7
- const ast = babylon.parseExpression(expr, {
8
+ const ast = babylon.parse(expr, {
8
9
  plugins: [
9
10
  'objectRestSpread'
10
11
  ]
11
12
  })
12
- if (t.isObjectExpression(ast)) {
13
- ast.properties.forEach((property) => {
14
- if (t.isObjectProperty(property) && !property.computed) {
15
- const propertyName = property.key.name || property.key.value
16
- if (/-/.test(propertyName)) {
17
- if (/\$/.test(propertyName)) {
18
- error && error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
13
+ traverse(ast, {
14
+ ObjectExpression (path) {
15
+ path.node.properties.forEach((property) => {
16
+ if (t.isObjectProperty(property) && !property.computed) {
17
+ const propertyName = property.key.name || property.key.value
18
+ if (/-/.test(propertyName)) {
19
+ if (/\$/.test(propertyName)) {
20
+ error && error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
21
+ } else {
22
+ property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
23
+ }
19
24
  } else {
20
- property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
25
+ property.key = t.identifier(propertyName)
21
26
  }
22
27
  }
23
- }
24
- })
25
- }
26
- return generate(ast, {
28
+ })
29
+ }
30
+ })
31
+ return generate(ast.program.body[0].expression, {
27
32
  compact: true
28
33
  }).code
29
34
  } catch (e) {
@@ -99,7 +99,7 @@ module.exports = function (content) {
99
99
  case config[mode].wxs.tag:
100
100
  // 显式传递issuerResource避免模块缓存以及提供给wxs-loader计算相对路径
101
101
  extraOptions = {
102
- issuerFile: mpx.getExtractedFile(this.resource),
102
+ issuerResource: this.resource,
103
103
  isStatic: true
104
104
  }
105
105
  requestString = getRequestString('wxs', { src, mode: localSrcMode }, extraOptions)
@@ -73,7 +73,7 @@ module.exports = function (content, map) {
73
73
  } else {
74
74
  const requestString = getRequestString('styles', { src: imp.url }, {
75
75
  isStatic: true,
76
- issuerFile: mpx.getExtractedFile(this.resource),
76
+ issuerResource: this.resource,
77
77
  fromImport: true
78
78
  }, i)
79
79
  return 'exports.push([module.id, ' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.3",
3
+ "version": "2.7.7",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -80,5 +80,5 @@
80
80
  "engines": {
81
81
  "node": ">=14.14.0"
82
82
  },
83
- "gitHead": "0cb7ce760316aa22f7c96ba8561a96f3eab2b8d6"
83
+ "gitHead": "53b05609117a347648f6cbb58693b25424a20ea9"
84
84
  }