@mpxjs/webpack-plugin 2.8.16 → 2.8.18

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
@@ -18,15 +18,17 @@ const AppEntryDependency = require('./dependencies/AppEntryDependency')
18
18
  const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
19
19
  const RecordVueContentDependency = require('./dependencies/RecordVueContentDependency')
20
20
  const CommonJsVariableDependency = require('./dependencies/CommonJsVariableDependency')
21
+ const tsWatchRunLoaderFilter = require('./utils/ts-loader-watch-run-loader-filter')
21
22
  const { MPX_APP_MODULE_ID } = require('./utils/const')
22
23
  const path = require('path')
23
24
 
24
25
  module.exports = function (content) {
25
26
  this.cacheable()
26
27
 
27
- // 兼容处理处理ts-loader中watch-run/updateFile逻辑,直接跳过当前loader及后续的vue-loader返回内容
28
- if (path.extname(this.resourcePath) === '.ts') {
29
- this.loaderIndex -= 2
28
+ // 兼容处理处理ts-loader中watch-run/updateFile逻辑,直接跳过当前loader及后续的loader返回内容
29
+ const pathExtname = path.extname(this.resourcePath)
30
+ if (!['.vue', '.mpx'].includes(pathExtname)) {
31
+ this.loaderIndex = tsWatchRunLoaderFilter(this.loaders, this.loaderIndex)
30
32
  return content
31
33
  }
32
34
 
@@ -1,6 +1,10 @@
1
1
  const runRules = require('../../run-rules')
2
2
  const normalizeTest = require('../normalize-test')
3
3
  const changeKey = require('../change-key')
4
+ const normalize = require('../../../utils/normalize')
5
+
6
+ const mpxViewPath = normalize.lib('runtime/components/ali/mpx-view.mpx')
7
+ const mpxTextPath = normalize.lib('runtime/components/ali/mpx-text.mpx')
4
8
 
5
9
  module.exports = function getSpec ({ warn, error }) {
6
10
  function print (mode, path, isError) {
@@ -38,6 +42,30 @@ module.exports = function getSpec ({ warn, error }) {
38
42
  return input
39
43
  }
40
44
 
45
+ // 处理支付宝 componentPlaceholder 不支持 view、text 原生标签
46
+ function aliComponentPlaceholderFallback (input) {
47
+ const componentPlaceholder = input.componentPlaceholder
48
+ const usingComponents = input.usingComponents || (input.usingComponents = {})
49
+ for (const cph in componentPlaceholder) {
50
+ const cur = componentPlaceholder[cph]
51
+ const placeholderCompMatched = cur.match(/^(?:view|text)$/g)
52
+ if (!Array.isArray(placeholderCompMatched)) continue
53
+ let compName, compPath
54
+ switch (placeholderCompMatched[0]) {
55
+ case 'view':
56
+ compName = 'mpx-view'
57
+ compPath = mpxViewPath
58
+ break
59
+ case 'text':
60
+ compName = 'mpx-text'
61
+ compPath = mpxTextPath
62
+ }
63
+ usingComponents[compName] = compPath
64
+ componentPlaceholder[cph] = compName
65
+ }
66
+ return input
67
+ }
68
+
41
69
  const spec = {
42
70
  supportedModes: ['ali', 'swan', 'qq', 'tt', 'jd', 'qa', 'dd'],
43
71
  normalizeTest,
@@ -99,6 +127,10 @@ module.exports = function getSpec ({ warn, error }) {
99
127
  tt: deletePath(),
100
128
  jd: deletePath()
101
129
  },
130
+ {
131
+ test: 'componentPlaceholder',
132
+ ali: aliComponentPlaceholderFallback
133
+ },
102
134
  {
103
135
  ali: addGlobalComponents,
104
136
  swan: addGlobalComponents,
@@ -112,6 +144,10 @@ module.exports = function getSpec ({ warn, error }) {
112
144
  test: 'componentGenerics',
113
145
  ali: deletePath(true)
114
146
  },
147
+ {
148
+ test: 'componentPlaceholder',
149
+ ali: aliComponentPlaceholderFallback
150
+ },
115
151
  {
116
152
  ali: addGlobalComponents,
117
153
  swan: addGlobalComponents,
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <text><slot></slot></text>
3
+ </template>
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <view><slot></slot></view>
3
+ </template>
package/lib/selector.js CHANGED
@@ -1,9 +1,16 @@
1
+ const path = require('path')
1
2
  const parseComponent = require('./parser')
2
3
  const parseRequest = require('./utils/parse-request')
4
+ const tsWatchRunLoaderFilter = require('./utils/ts-loader-watch-run-loader-filter')
3
5
 
4
6
  module.exports = function (content) {
5
7
  this.cacheable()
6
-
8
+ // 兼容处理处理ts-loader中watch-run/updateFile逻辑,直接跳过当前loader及后续的loader返回内容
9
+ const pathExtname = path.extname(this.resourcePath)
10
+ if (!['.vue', '.mpx'].includes(pathExtname)) {
11
+ this.loaderIndex = tsWatchRunLoaderFilter(this.loaders, this.loaderIndex)
12
+ return content
13
+ }
7
14
  // 移除mpx访问依赖,支持 thread-loader
8
15
  const { mode, env } = this.getOptions() || {}
9
16
  if (!mode && !env) {
@@ -4,7 +4,7 @@ module.exports = function (loaderContext) {
4
4
  let entryName = ''
5
5
  for (const [name, { dependencies }] of loaderContext._compilation.entries) {
6
6
  const entryModule = moduleGraph.getModule(dependencies[0])
7
- if (entryModule.resource === loaderContext.resource) {
7
+ if (entryModule && entryModule.resource === loaderContext.resource) {
8
8
  entryName = name
9
9
  break
10
10
  }
@@ -0,0 +1,23 @@
1
+ const normalize = require('./normalize')
2
+ const selectorPath = normalize.lib('selector.js')
3
+ const scriptSetupPath = normalize.lib('script-setup-compiler/index.js')
4
+ const mpxLoaderPath = normalize.lib('loader.js')
5
+ const { has } = require('./set')
6
+
7
+ const tsLoaderWatchRunFilterLoaders = new Set([
8
+ selectorPath,
9
+ scriptSetupPath,
10
+ mpxLoaderPath,
11
+ 'node_modules/vue-loader/lib/index.js'
12
+ ])
13
+
14
+ module.exports = (loaders, loaderIndex) => {
15
+ for (let len = loaders.length; len > 0; --len) {
16
+ const currentLoader = loaders[len - 1]
17
+ if (!has(tsLoaderWatchRunFilterLoaders, filterLoaderPath => currentLoader.path.endsWith(filterLoaderPath))) {
18
+ break
19
+ }
20
+ loaderIndex--
21
+ }
22
+ return loaderIndex
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.16",
3
+ "version": "2.8.18",
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": "79e2edd884ef6b27593952950f72343b98849bd7"
85
+ "gitHead": "fd022afc8f403756de44c9eaab105a5a689e9b07"
86
86
  }