@mpxjs/webpack-plugin 2.9.8 → 2.9.9
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 +1 -1
- package/lib/json-compiler/index.js +10 -3
- package/lib/runtime/components/web/mpx-movable-view.vue +1 -1
- package/lib/runtime/optionProcessor.d.ts +3 -1
- package/lib/runtime/optionProcessor.js +8 -9
- package/lib/script-setup-compiler/index.js +1 -1
- package/lib/template-compiler/bind-this.js +22 -8
- package/lib/template-compiler/compiler.js +1 -1
- package/lib/utils/get-entry-name.js +6 -4
- package/lib/web/processMainScript.js +3 -1
- package/lib/web/processScript.js +2 -2
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1089,7 +1089,7 @@ class MpxWebpackPlugin {
|
|
|
1089
1089
|
if (tarRoot) {
|
|
1090
1090
|
// 删除root query
|
|
1091
1091
|
if (queryObj.root) request = addQuery(request, {}, false, ['root'])
|
|
1092
|
-
//
|
|
1092
|
+
// wx、ali(需开启enableAliRequireAsync)和web平台支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
|
|
1093
1093
|
if (mpx.supportRequireAsync) {
|
|
1094
1094
|
if (mpx.mode === 'web') {
|
|
1095
1095
|
const depBlock = new AsyncDependenciesBlock(
|
|
@@ -14,6 +14,9 @@ const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalCo
|
|
|
14
14
|
const RecordIndependentDependency = require('../dependencies/RecordIndependentDependency')
|
|
15
15
|
const { MPX_DISABLE_EXTRACTOR_CACHE, RESOLVE_IGNORED_ERR, JSON_JS_EXT } = require('../utils/const')
|
|
16
16
|
const resolve = require('../utils/resolve')
|
|
17
|
+
const normalize = require('../utils/normalize')
|
|
18
|
+
const mpxViewPath = normalize.lib('runtime/components/ali/mpx-view.mpx')
|
|
19
|
+
const mpxTextPath = normalize.lib('runtime/components/ali/mpx-text.mpx')
|
|
17
20
|
|
|
18
21
|
module.exports = function (content) {
|
|
19
22
|
const nativeCallback = this.async()
|
|
@@ -65,9 +68,13 @@ module.exports = function (content) {
|
|
|
65
68
|
}
|
|
66
69
|
const normalizePlaceholder = (placeholder) => {
|
|
67
70
|
if (typeof placeholder === 'string') {
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
const placeholderMap = mode === 'ali'
|
|
72
|
+
? {
|
|
73
|
+
view: { name: 'mpx-view', resource: mpxViewPath },
|
|
74
|
+
text: { name: 'mpx-text', resource: mpxTextPath }
|
|
70
75
|
}
|
|
76
|
+
: {}
|
|
77
|
+
placeholder = placeholderMap[placeholder] || { name: placeholder }
|
|
71
78
|
}
|
|
72
79
|
if (!placeholder.name) {
|
|
73
80
|
emitError('The asyncSubpackageRules configuration format of @mpxjs/webpack-plugin a is incorrect')
|
|
@@ -211,7 +218,7 @@ module.exports = function (content) {
|
|
|
211
218
|
const processComponents = (components, context, callback) => {
|
|
212
219
|
if (components) {
|
|
213
220
|
async.eachOf(components, (component, name, callback) => {
|
|
214
|
-
processComponent(component, context, { relativePath }, (err, entry, { tarRoot, placeholder }) => {
|
|
221
|
+
processComponent(component, context, { relativePath }, (err, entry, { tarRoot, placeholder } = {}) => {
|
|
215
222
|
if (err === RESOLVE_IGNORED_ERR) {
|
|
216
223
|
delete components[name]
|
|
217
224
|
return callback()
|
|
@@ -6,8 +6,10 @@ declare global {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export function processComponentOption (...args: any): object
|
|
10
10
|
|
|
11
11
|
export function getComponent (...args: any): object
|
|
12
12
|
|
|
13
13
|
export function getWxsMixin (...args: any): object
|
|
14
|
+
|
|
15
|
+
export function processAppOption (...args: any): void
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { hasOwn } from './utils'
|
|
1
|
+
import { hasOwn, isEmptyObject } from './utils'
|
|
2
2
|
import { isBrowser } from './env'
|
|
3
3
|
import transRpxStyle from './transRpxStyle'
|
|
4
4
|
import animation from './animation'
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export function processComponentOption (
|
|
7
7
|
{
|
|
8
8
|
option,
|
|
9
9
|
ctorType,
|
|
@@ -12,7 +12,7 @@ export default function processComponentOption (
|
|
|
12
12
|
componentsMap,
|
|
13
13
|
componentGenerics,
|
|
14
14
|
genericsInfo,
|
|
15
|
-
|
|
15
|
+
wxsMixin,
|
|
16
16
|
hasApp
|
|
17
17
|
}
|
|
18
18
|
) {
|
|
@@ -40,7 +40,7 @@ registered in parent context!`)
|
|
|
40
40
|
})
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
if (componentGenerics) {
|
|
43
|
+
if (!isEmptyObject(componentGenerics)) {
|
|
44
44
|
option.props = option.props || {}
|
|
45
45
|
option.props.generichash = String
|
|
46
46
|
Object.keys(componentGenerics).forEach((genericName) => {
|
|
@@ -64,10 +64,9 @@ registered in parent context!`)
|
|
|
64
64
|
option.filters = { transRpxStyle }
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
if (
|
|
68
|
-
option.mixins.
|
|
69
|
-
|
|
70
|
-
option.mixins = [mixin]
|
|
67
|
+
if (wxsMixin) {
|
|
68
|
+
option.mixins = option.mixins || []
|
|
69
|
+
option.mixins.push(wxsMixin)
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
if (outputPath) {
|
|
@@ -85,7 +84,7 @@ export function getComponent (component, extendOptions) {
|
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
export function getWxsMixin (wxsModules) {
|
|
88
|
-
if (!wxsModules || !Object.keys(wxsModules).length) return
|
|
87
|
+
if (!wxsModules || !Object.keys(wxsModules).length) return
|
|
89
88
|
return {
|
|
90
89
|
created () {
|
|
91
90
|
Object.keys(wxsModules).forEach((key) => {
|
|
@@ -96,12 +96,11 @@ function checkDelAndGetPath (path) {
|
|
|
96
96
|
} else {
|
|
97
97
|
delPath = current.parentPath
|
|
98
98
|
}
|
|
99
|
-
} else if (t.isLogicalExpression(current.container)) { // case: a || ''
|
|
99
|
+
} else if (t.isLogicalExpression(current.container)) { // 只处理case: a || '' or '123' || a
|
|
100
100
|
const key = current.key === 'left' ? 'right' : 'left'
|
|
101
101
|
if (t.isLiteral(current.parent[key])) {
|
|
102
102
|
delPath = current.parentPath
|
|
103
103
|
} else {
|
|
104
|
-
canDel = false
|
|
105
104
|
break
|
|
106
105
|
}
|
|
107
106
|
} else if (current.key === 'expression' && t.isExpressionStatement(current.parentPath)) { // dealRemove删除节点时需要
|
|
@@ -116,11 +115,23 @@ function checkDelAndGetPath (path) {
|
|
|
116
115
|
// 确定是否可删除
|
|
117
116
|
while (!t.isBlockStatement(current) && canDel) {
|
|
118
117
|
const { key, container } = current
|
|
118
|
+
if (t.isIfStatement(container) && key === 'test') { // if (a) {}
|
|
119
|
+
canDel = false
|
|
120
|
+
break
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (t.isLogicalExpression(container)) { // case: a || ((b || c) && d)
|
|
124
|
+
ignore = true
|
|
125
|
+
break
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// case: a ??= b
|
|
119
129
|
if (
|
|
120
|
-
|
|
121
|
-
|
|
130
|
+
key === 'right' &&
|
|
131
|
+
t.isAssignmentExpression(container) &&
|
|
132
|
+
['??=', '||=', '&&='].includes(container.operator)
|
|
122
133
|
) {
|
|
123
|
-
|
|
134
|
+
ignore = true
|
|
124
135
|
break
|
|
125
136
|
}
|
|
126
137
|
|
|
@@ -166,13 +177,16 @@ function dealRemove (path, replace) {
|
|
|
166
177
|
if (replace) {
|
|
167
178
|
path.replaceWith(t.stringLiteral(''))
|
|
168
179
|
} else {
|
|
169
|
-
|
|
180
|
+
if (path.inList) {
|
|
181
|
+
t.validate(path.parent, path.key, [null])
|
|
182
|
+
} else {
|
|
183
|
+
t.validate(path.parent, path.key, null)
|
|
184
|
+
}
|
|
170
185
|
path.remove()
|
|
171
186
|
}
|
|
172
187
|
delete path.needBind
|
|
173
188
|
delete path.collectInfo
|
|
174
|
-
} catch (e) {
|
|
175
|
-
}
|
|
189
|
+
} catch (e) {}
|
|
176
190
|
}
|
|
177
191
|
|
|
178
192
|
module.exports = {
|
|
@@ -1931,7 +1931,7 @@ function postProcessTemplate (el) {
|
|
|
1931
1931
|
}
|
|
1932
1932
|
}
|
|
1933
1933
|
|
|
1934
|
-
const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,noMode')
|
|
1934
|
+
const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,noMode')
|
|
1935
1935
|
|
|
1936
1936
|
const wrapRE = /^\((.*)\)$/
|
|
1937
1937
|
|
|
@@ -3,10 +3,12 @@ module.exports = function (loaderContext) {
|
|
|
3
3
|
const moduleGraph = loaderContext._compilation.moduleGraph
|
|
4
4
|
let entryName = ''
|
|
5
5
|
for (const [name, { dependencies }] of loaderContext._compilation.entries) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
for (const dep of dependencies) {
|
|
7
|
+
const entryModule = moduleGraph.getModule(dep)
|
|
8
|
+
if (entryModule && entryModule.resource === loaderContext.resource) {
|
|
9
|
+
entryName = name
|
|
10
|
+
break
|
|
11
|
+
}
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
return entryName
|
|
@@ -46,7 +46,6 @@ module.exports = function (script, {
|
|
|
46
46
|
output += ` import Vue from 'vue'
|
|
47
47
|
import VueRouter from 'vue-router'
|
|
48
48
|
import Mpx from '@mpxjs/core'
|
|
49
|
-
import App from ${stringifyRequest(loaderContext, addQuery(resource, { isApp: true }))}
|
|
50
49
|
import { processAppOption, getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
|
|
51
50
|
Vue.use(VueRouter)\n`
|
|
52
51
|
|
|
@@ -64,6 +63,9 @@ module.exports = function (script, {
|
|
|
64
63
|
isMain: true,
|
|
65
64
|
globalTabBar
|
|
66
65
|
})
|
|
66
|
+
|
|
67
|
+
output += `\n const App = require(${stringifyRequest(loaderContext, addQuery(resource, { isApp: true }))}).default\n`
|
|
68
|
+
|
|
67
69
|
output += `
|
|
68
70
|
export default processAppOption({
|
|
69
71
|
App,
|
package/lib/web/processScript.js
CHANGED
|
@@ -40,7 +40,7 @@ module.exports = function (script, {
|
|
|
40
40
|
return attrs
|
|
41
41
|
},
|
|
42
42
|
content (script) {
|
|
43
|
-
let content = `\n import processComponentOption,
|
|
43
|
+
let content = `\n import { processComponentOption, getComponent, getWxsMixin } from ${stringifyRequest(optionProcessorPath)}\n`
|
|
44
44
|
let hasApp = true
|
|
45
45
|
if (!appInfo.name) {
|
|
46
46
|
hasApp = false
|
|
@@ -85,7 +85,7 @@ module.exports = function (script, {
|
|
|
85
85
|
componentsMap: ${shallowStringify(componentsMap)},
|
|
86
86
|
componentGenerics: ${JSON.stringify(componentGenerics)},
|
|
87
87
|
genericsInfo: ${JSON.stringify(genericsInfo)},
|
|
88
|
-
|
|
88
|
+
wxsMixin: getWxsMixin(wxsModules),
|
|
89
89
|
hasApp: ${hasApp}
|
|
90
90
|
})\n`
|
|
91
91
|
return content
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.9",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"engines": {
|
|
84
84
|
"node": ">=14.14.0"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "7ec6526f024c00f9c6b935c631bfdc61be27b69b"
|
|
87
87
|
}
|