@mpxjs/webpack-plugin 2.7.40 → 2.7.44
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
|
@@ -164,12 +164,6 @@ class MpxWebpackPlugin {
|
|
|
164
164
|
}, options.nativeConfig)
|
|
165
165
|
options.webConfig = options.webConfig || {}
|
|
166
166
|
options.partialCompile = options.mode !== 'web' && options.partialCompile
|
|
167
|
-
let proxyComponentEventsRules = []
|
|
168
|
-
const proxyComponentEventsRulesRaw = options.proxyComponentEventsRules
|
|
169
|
-
if (proxyComponentEventsRulesRaw) {
|
|
170
|
-
proxyComponentEventsRules = Array.isArray(proxyComponentEventsRulesRaw) ? proxyComponentEventsRulesRaw : [proxyComponentEventsRulesRaw]
|
|
171
|
-
}
|
|
172
|
-
options.proxyComponentEventsRules = proxyComponentEventsRules
|
|
173
167
|
this.options = options
|
|
174
168
|
// Hack for buildDependencies
|
|
175
169
|
const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
|
|
@@ -574,7 +568,6 @@ class MpxWebpackPlugin {
|
|
|
574
568
|
useRelativePath: this.options.useRelativePath,
|
|
575
569
|
removedChunks: [],
|
|
576
570
|
forceProxyEventRules: this.options.forceProxyEventRules,
|
|
577
|
-
proxyComponentEventsRules: this.options.proxyComponentEventsRules,
|
|
578
571
|
pathHash: (resourcePath) => {
|
|
579
572
|
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
|
|
580
573
|
return hash(path.relative(this.options.projectRoot, resourcePath))
|
|
@@ -819,12 +812,24 @@ class MpxWebpackPlugin {
|
|
|
819
812
|
// 因为文件缓存的存在,前面hack identifier的行为对于从文件缓存中创建得到的module并不生效,因此需要在回调中进行二次hack处理
|
|
820
813
|
if (err) return rawCallback(err)
|
|
821
814
|
hackModuleIdentifier(module)
|
|
822
|
-
rawCallback(null, module)
|
|
815
|
+
return rawCallback(null, module)
|
|
823
816
|
}
|
|
824
817
|
}
|
|
825
818
|
return rawAddModule.call(compilation, module, callback)
|
|
826
819
|
}
|
|
827
820
|
|
|
821
|
+
// hack process https://github.com/webpack/webpack/issues/16045
|
|
822
|
+
const _handleModuleBuildAndDependenciesRaw = compilation._handleModuleBuildAndDependencies
|
|
823
|
+
|
|
824
|
+
compilation._handleModuleBuildAndDependencies = (originModule, module, recursive, callback) => {
|
|
825
|
+
const rawCallback = callback
|
|
826
|
+
callback = (err) => {
|
|
827
|
+
if (err) return rawCallback(err)
|
|
828
|
+
return rawCallback(null, module)
|
|
829
|
+
}
|
|
830
|
+
return _handleModuleBuildAndDependenciesRaw.call(compilation, originModule, module, recursive, callback)
|
|
831
|
+
}
|
|
832
|
+
|
|
828
833
|
const rawEmitAsset = compilation.emitAsset
|
|
829
834
|
|
|
830
835
|
compilation.emitAsset = (file, source, assetInfo) => {
|
|
@@ -957,7 +962,7 @@ class MpxWebpackPlugin {
|
|
|
957
962
|
return true
|
|
958
963
|
})
|
|
959
964
|
|
|
960
|
-
const requireAsyncHandler = (expr, members) => {
|
|
965
|
+
const requireAsyncHandler = (expr, members, args) => {
|
|
961
966
|
if (members[0] === 'async') {
|
|
962
967
|
let request = expr.arguments[0].value
|
|
963
968
|
const range = expr.arguments[0].range
|
|
@@ -977,10 +982,10 @@ class MpxWebpackPlugin {
|
|
|
977
982
|
const dep = new CommonJsAsyncDependency(request, range)
|
|
978
983
|
parser.state.current.addDependency(dep)
|
|
979
984
|
}
|
|
985
|
+
if (args) parser.walkExpressions(args)
|
|
980
986
|
return true
|
|
981
987
|
} else {
|
|
982
988
|
compilation.errors.push(new Error(`The require async JS [${request}] need to declare subpackage name by root`))
|
|
983
|
-
return true
|
|
984
989
|
}
|
|
985
990
|
}
|
|
986
991
|
}
|
|
@@ -997,7 +1002,7 @@ class MpxWebpackPlugin {
|
|
|
997
1002
|
.tap({
|
|
998
1003
|
name: 'MpxWebpackPlugin',
|
|
999
1004
|
stage: -1000
|
|
1000
|
-
}, (expr, calleeMembers, callExpr) => requireAsyncHandler(callExpr, calleeMembers))
|
|
1005
|
+
}, (expr, calleeMembers, callExpr) => requireAsyncHandler(callExpr, calleeMembers, expr.arguments))
|
|
1001
1006
|
|
|
1002
1007
|
// hack babel polyfill global
|
|
1003
1008
|
parser.hooks.statementIf.tap('MpxWebpackPlugin', (expr) => {
|
package/lib/loader.js
CHANGED
|
@@ -126,11 +126,12 @@ module.exports = function (content) {
|
|
|
126
126
|
if (mode === 'web') {
|
|
127
127
|
if (ctorType === 'app' && !queryObj.isApp) {
|
|
128
128
|
const request = addQuery(this.resource, { isApp: true })
|
|
129
|
+
const el = mpx.webConfig.el || '#app'
|
|
129
130
|
output += `
|
|
130
131
|
import App from ${stringifyRequest(request)}
|
|
131
132
|
import Vue from 'vue'
|
|
132
133
|
new Vue({
|
|
133
|
-
el: '
|
|
134
|
+
el: '${el}',
|
|
134
135
|
render: function(h){
|
|
135
136
|
return h(App)
|
|
136
137
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isEmptyObject } from './util'
|
|
2
|
-
const isTouchDevice = 'ontouchstart' in document.documentElement
|
|
2
|
+
const isTouchDevice = document && ('ontouchstart' in document.documentElement)
|
|
3
3
|
|
|
4
4
|
function processModel (listeners, context) {
|
|
5
5
|
// 该函数只有wx:model的情况下才调用,而且默认e.detail.value有值
|
|
@@ -3,6 +3,7 @@ const he = require('he')
|
|
|
3
3
|
const config = require('../config')
|
|
4
4
|
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
|
|
5
5
|
const normalize = require('../utils/normalize')
|
|
6
|
+
const { normalizeCondition } = require('../utils/match-condition')
|
|
6
7
|
const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
|
|
7
8
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
8
9
|
const getRulesRunner = require('../platform/index')
|
|
@@ -10,7 +11,6 @@ const addQuery = require('../utils/add-query')
|
|
|
10
11
|
const transDynamicClassExpr = require('./trans-dynamic-class-expr')
|
|
11
12
|
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
12
13
|
const { inBrowser } = require('../utils/env')
|
|
13
|
-
const { matchCondition } = require('../utils/match-condition')
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Make a map and return a function for checking if a key
|
|
@@ -746,7 +746,7 @@ function parse (template, options) {
|
|
|
746
746
|
stack.push(element)
|
|
747
747
|
} else {
|
|
748
748
|
element.unary = true
|
|
749
|
-
closeElement(element, meta)
|
|
749
|
+
closeElement(element, meta, options)
|
|
750
750
|
}
|
|
751
751
|
},
|
|
752
752
|
|
|
@@ -761,7 +761,7 @@ function parse (template, options) {
|
|
|
761
761
|
// pop stack
|
|
762
762
|
stack.pop()
|
|
763
763
|
currentParent = stack[stack.length - 1]
|
|
764
|
-
closeElement(element, meta)
|
|
764
|
+
closeElement(element, meta, options)
|
|
765
765
|
}
|
|
766
766
|
},
|
|
767
767
|
|
|
@@ -1813,57 +1813,67 @@ function processBuiltInComponents (el, meta) {
|
|
|
1813
1813
|
}
|
|
1814
1814
|
}
|
|
1815
1815
|
|
|
1816
|
-
function
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
const events = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
|
|
1837
|
-
fallThroughEvents = Array.from(new Set(fallThroughEvents.concat(events)))
|
|
1838
|
-
break
|
|
1839
|
-
}
|
|
1816
|
+
function processAliAddComponentRootView (el, options) {
|
|
1817
|
+
const processAttrsConditions = [
|
|
1818
|
+
{ condition: /^(on|catch)Tap$/, action: 'clone' },
|
|
1819
|
+
{ condition: /^(on|catch)TouchStart$/, action: 'clone' },
|
|
1820
|
+
{ condition: /^(on|catch)TouchMove$/, action: 'clone' },
|
|
1821
|
+
{ condition: /^(on|catch)TouchEnd$/, action: 'clone' },
|
|
1822
|
+
{ condition: /^(on|catch)TouchCancel$/, action: 'clone' },
|
|
1823
|
+
{ condition: /^(on|catch)LongTap$/, action: 'clone' },
|
|
1824
|
+
{ condition: /^data-/, action: 'clone' },
|
|
1825
|
+
{ condition: /^style$/, action: 'move' },
|
|
1826
|
+
{ condition: /^slot$/, action: 'move' }
|
|
1827
|
+
]
|
|
1828
|
+
const processAppendAttrsRules = [
|
|
1829
|
+
{ name: 'class', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
|
|
1830
|
+
]
|
|
1831
|
+
let newElAttrs = []
|
|
1832
|
+
let allAttrs = cloneAttrsList(el.attrsList)
|
|
1833
|
+
|
|
1834
|
+
function processClone (attr) {
|
|
1835
|
+
newElAttrs.push(attr)
|
|
1840
1836
|
}
|
|
1841
1837
|
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
}])
|
|
1847
|
-
})
|
|
1848
|
-
}
|
|
1838
|
+
function processMove (attr) {
|
|
1839
|
+
getAndRemoveAttr(el, attr.name)
|
|
1840
|
+
newElAttrs.push(attr)
|
|
1841
|
+
}
|
|
1849
1842
|
|
|
1850
|
-
function
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1843
|
+
function processAppendRules (el) {
|
|
1844
|
+
processAppendAttrsRules.forEach((rule) => {
|
|
1845
|
+
const getNeedAppendAttrValue = el.attrsMap[rule.name]
|
|
1846
|
+
const value = getNeedAppendAttrValue ? getNeedAppendAttrValue + ' ' + rule.value : rule.value
|
|
1847
|
+
newElAttrs.push({
|
|
1848
|
+
name: rule.name,
|
|
1849
|
+
value
|
|
1850
|
+
})
|
|
1851
|
+
})
|
|
1852
|
+
}
|
|
1858
1853
|
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1854
|
+
processAttrsConditions.forEach(item => {
|
|
1855
|
+
const matcher = normalizeCondition(item.condition)
|
|
1856
|
+
allAttrs.forEach((attr) => {
|
|
1857
|
+
if (matcher(attr.name)) {
|
|
1858
|
+
if (item.action === 'clone') {
|
|
1859
|
+
processClone(attr)
|
|
1860
|
+
} else if (item.action === 'move') {
|
|
1861
|
+
processMove(attr)
|
|
1862
|
+
}
|
|
1864
1863
|
}
|
|
1865
1864
|
})
|
|
1865
|
+
})
|
|
1866
|
+
|
|
1867
|
+
processAppendRules(el)
|
|
1868
|
+
let componentWrapView = createASTElement('view', newElAttrs)
|
|
1869
|
+
moveBaseDirective(componentWrapView, el)
|
|
1870
|
+
if (el.is && el.components) {
|
|
1871
|
+
el = postProcessComponentIs(el)
|
|
1866
1872
|
}
|
|
1873
|
+
|
|
1874
|
+
replaceNode(el, componentWrapView, true)
|
|
1875
|
+
addChild(componentWrapView, el)
|
|
1876
|
+
return componentWrapView
|
|
1867
1877
|
}
|
|
1868
1878
|
|
|
1869
1879
|
// 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
|
|
@@ -1875,36 +1885,36 @@ function getVirtualHostRoot (options, meta) {
|
|
|
1875
1885
|
!meta.options && (meta.options = {})
|
|
1876
1886
|
meta.options.virtualHost = true
|
|
1877
1887
|
}
|
|
1878
|
-
if (mode === 'ali' && !options.hasVirtualHost) {
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
}
|
|
1888
|
+
// if (mode === 'ali' && !options.hasVirtualHost) {
|
|
1889
|
+
// // ali组件根节点实体化
|
|
1890
|
+
// let rootView = createASTElement('view', [
|
|
1891
|
+
// {
|
|
1892
|
+
// name: 'class',
|
|
1893
|
+
// value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
|
|
1894
|
+
// }
|
|
1895
|
+
// ])
|
|
1896
|
+
// processElement(rootView, rootView, options, meta)
|
|
1897
|
+
// return rootView
|
|
1898
|
+
// }
|
|
1889
1899
|
}
|
|
1890
1900
|
return getTempNode()
|
|
1891
1901
|
}
|
|
1892
1902
|
|
|
1893
1903
|
function processShow (el, options, root) {
|
|
1904
|
+
// 开启 virtualhost 全部走 props 传递处理
|
|
1905
|
+
// 未开启 virtualhost 直接绑定 display:none 到节点上
|
|
1894
1906
|
let show = getAndRemoveAttr(el, config[mode].directive.show).val
|
|
1895
1907
|
if (mode === 'swan') show = wrapMustache(show)
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1908
|
+
|
|
1909
|
+
if (options.hasVirtualHost) {
|
|
1910
|
+
if (options.isComponent && el.parent === root && isRealNode(el)) {
|
|
1911
|
+
if (show !== undefined) {
|
|
1912
|
+
show = `{{${parseMustache(show).result}&&mpxShow}}`
|
|
1913
|
+
} else {
|
|
1914
|
+
show = '{{mpxShow}}'
|
|
1915
|
+
}
|
|
1904
1916
|
}
|
|
1905
|
-
|
|
1906
|
-
if (show !== undefined) {
|
|
1907
|
-
if (isComponentNode(el, options)) {
|
|
1917
|
+
if (isComponentNode(el, options) && show !== undefined) {
|
|
1908
1918
|
if (show === '') {
|
|
1909
1919
|
show = '{{false}}'
|
|
1910
1920
|
}
|
|
@@ -1913,6 +1923,14 @@ function processShow (el, options, root) {
|
|
|
1913
1923
|
value: show
|
|
1914
1924
|
}])
|
|
1915
1925
|
} else {
|
|
1926
|
+
processShowStyle()
|
|
1927
|
+
}
|
|
1928
|
+
} else {
|
|
1929
|
+
processShowStyle()
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
function processShowStyle () {
|
|
1933
|
+
if (show !== undefined) {
|
|
1916
1934
|
const showExp = parseMustache(show).result
|
|
1917
1935
|
let oldStyle = getAndRemoveAttr(el, 'style').val
|
|
1918
1936
|
oldStyle = oldStyle ? oldStyle + ';' : ''
|
|
@@ -2094,11 +2112,6 @@ function processElement (el, root, options, meta) {
|
|
|
2094
2112
|
processShow(el, options, root)
|
|
2095
2113
|
}
|
|
2096
2114
|
|
|
2097
|
-
if (transAli) {
|
|
2098
|
-
processAliStyleClassHack(el, options, root)
|
|
2099
|
-
processAliEventHack(el, options, root)
|
|
2100
|
-
}
|
|
2101
|
-
|
|
2102
2115
|
if (!pass) {
|
|
2103
2116
|
processBindEvent(el, options)
|
|
2104
2117
|
processComponentIs(el, options)
|
|
@@ -2107,7 +2120,7 @@ function processElement (el, root, options, meta) {
|
|
|
2107
2120
|
processAttrs(el, options)
|
|
2108
2121
|
}
|
|
2109
2122
|
|
|
2110
|
-
function closeElement (el, meta) {
|
|
2123
|
+
function closeElement (el, meta, options) {
|
|
2111
2124
|
postProcessAtMode(el)
|
|
2112
2125
|
if (mode === 'web') {
|
|
2113
2126
|
postProcessWxs(el, meta)
|
|
@@ -2117,8 +2130,13 @@ function closeElement (el, meta) {
|
|
|
2117
2130
|
}
|
|
2118
2131
|
const pass = isNative || postProcessTemplate(el) || processingTemplate
|
|
2119
2132
|
postProcessWxs(el, meta)
|
|
2133
|
+
|
|
2120
2134
|
if (!pass) {
|
|
2121
|
-
|
|
2135
|
+
if (isComponentNode(el, options) && !options.hasVirtualHost && mode === 'ali') {
|
|
2136
|
+
el = processAliAddComponentRootView(el, options)
|
|
2137
|
+
} else {
|
|
2138
|
+
el = postProcessComponentIs(el)
|
|
2139
|
+
}
|
|
2122
2140
|
}
|
|
2123
2141
|
postProcessFor(el)
|
|
2124
2142
|
postProcessIf(el)
|
|
@@ -59,8 +59,7 @@ module.exports = function (raw) {
|
|
|
59
59
|
checkUsingComponents: mpx.checkUsingComponents,
|
|
60
60
|
globalComponents: Object.keys(mpx.usingComponents),
|
|
61
61
|
forceProxyEvent: matchCondition(resourcePath, mpx.forceProxyEventRules),
|
|
62
|
-
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
|
|
63
|
-
proxyComponentEventsRules: mpx.proxyComponentEventsRules
|
|
62
|
+
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
|
|
64
63
|
})
|
|
65
64
|
|
|
66
65
|
if (meta.wxsContentMap) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.44",
|
|
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": "
|
|
83
|
+
"gitHead": "306aee23bc55c7f1af58b8de0c6e6394370c88d4"
|
|
84
84
|
}
|