@mpxjs/webpack-plugin 2.7.35 → 2.7.38
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 +7 -0
- package/lib/template-compiler/compiler.js +76 -94
- package/lib/template-compiler/index.js +2 -1
- package/lib/wxs/loader.js +3 -1
- package/lib/wxs/pre-loader.js +17 -1
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -164,6 +164,12 @@ 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
|
|
167
173
|
this.options = options
|
|
168
174
|
// Hack for buildDependencies
|
|
169
175
|
const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
|
|
@@ -568,6 +574,7 @@ class MpxWebpackPlugin {
|
|
|
568
574
|
useRelativePath: this.options.useRelativePath,
|
|
569
575
|
removedChunks: [],
|
|
570
576
|
forceProxyEventRules: this.options.forceProxyEventRules,
|
|
577
|
+
proxyComponentEventsRules: this.options.proxyComponentEventsRules,
|
|
571
578
|
pathHash: (resourcePath) => {
|
|
572
579
|
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
|
|
573
580
|
return hash(path.relative(this.options.projectRoot, resourcePath))
|
|
@@ -3,7 +3,6 @@ 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')
|
|
7
6
|
const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
|
|
8
7
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
9
8
|
const getRulesRunner = require('../platform/index')
|
|
@@ -11,6 +10,7 @@ const addQuery = require('../utils/add-query')
|
|
|
11
10
|
const transDynamicClassExpr = require('./trans-dynamic-class-expr')
|
|
12
11
|
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
13
12
|
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)
|
|
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)
|
|
765
765
|
}
|
|
766
766
|
},
|
|
767
767
|
|
|
@@ -1813,67 +1813,57 @@ function processBuiltInComponents (el, meta) {
|
|
|
1813
1813
|
}
|
|
1814
1814
|
}
|
|
1815
1815
|
|
|
1816
|
-
function
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
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)
|
|
1816
|
+
function processAliEventHack (el, options, root) {
|
|
1817
|
+
// 只处理组件根节点
|
|
1818
|
+
if (!(options.isComponent && el === root && isRealNode(el))) {
|
|
1819
|
+
return
|
|
1836
1820
|
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1821
|
+
const { proxyComponentEventsRules } = options
|
|
1822
|
+
let fallThroughEvents = ['onTap']
|
|
1823
|
+
// 判断当前文件是否在范围中
|
|
1824
|
+
const filePath = options.filePath
|
|
1825
|
+
for (let item of proxyComponentEventsRules) {
|
|
1826
|
+
const {
|
|
1827
|
+
include,
|
|
1828
|
+
exclude
|
|
1829
|
+
} = item || {}
|
|
1830
|
+
|
|
1831
|
+
if (matchCondition(filePath, {
|
|
1832
|
+
include,
|
|
1833
|
+
exclude
|
|
1834
|
+
})) {
|
|
1835
|
+
const eventsRaw = item.events
|
|
1836
|
+
const events = Array.isArray(eventsRaw) ? eventsRaw : [eventsRaw]
|
|
1837
|
+
fallThroughEvents = Array.from(new Set(fallThroughEvents.concat(events)))
|
|
1838
|
+
break
|
|
1839
|
+
}
|
|
1841
1840
|
}
|
|
1842
1841
|
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
})
|
|
1851
|
-
})
|
|
1852
|
-
}
|
|
1842
|
+
fallThroughEvents.forEach((type) => {
|
|
1843
|
+
addAttrs(el, [{
|
|
1844
|
+
name: type,
|
|
1845
|
+
value: '__proxyEvent'
|
|
1846
|
+
}])
|
|
1847
|
+
})
|
|
1848
|
+
}
|
|
1853
1849
|
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1850
|
+
function processAliStyleClassHack (el, options, root) {
|
|
1851
|
+
// 处理组件根节点
|
|
1852
|
+
if (options.isComponent && el === root && isRealNode(el)) {
|
|
1853
|
+
['style', 'class'].forEach((type) => {
|
|
1854
|
+
let exp = getAndRemoveAttr(el, type).val
|
|
1855
|
+
let typeName = type === 'class' ? 'className' : type
|
|
1856
|
+
let sep = type === 'style' ? ';' : ' '
|
|
1857
|
+
let newValue = exp ? `{{${typeName}||''}}${sep}${exp}` : `{{${typeName}||''}}`
|
|
1858
|
+
|
|
1859
|
+
if (newValue !== undefined) {
|
|
1860
|
+
addAttrs(el, [{
|
|
1861
|
+
name: type,
|
|
1862
|
+
value: newValue
|
|
1863
|
+
}])
|
|
1863
1864
|
}
|
|
1864
1865
|
})
|
|
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)
|
|
1872
1866
|
}
|
|
1873
|
-
|
|
1874
|
-
replaceNode(el, componentWrapView, true)
|
|
1875
|
-
addChild(componentWrapView, el)
|
|
1876
|
-
return componentWrapView
|
|
1877
1867
|
}
|
|
1878
1868
|
|
|
1879
1869
|
// 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
|
|
@@ -1885,36 +1875,36 @@ function getVirtualHostRoot (options, meta) {
|
|
|
1885
1875
|
!meta.options && (meta.options = {})
|
|
1886
1876
|
meta.options.virtualHost = true
|
|
1887
1877
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1878
|
+
if (mode === 'ali' && !options.hasVirtualHost) {
|
|
1879
|
+
// ali组件根节点实体化
|
|
1880
|
+
let rootView = createASTElement('view', [
|
|
1881
|
+
{
|
|
1882
|
+
name: 'class',
|
|
1883
|
+
value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
|
|
1884
|
+
}
|
|
1885
|
+
])
|
|
1886
|
+
processElement(rootView, rootView, options, meta)
|
|
1887
|
+
return rootView
|
|
1888
|
+
}
|
|
1899
1889
|
}
|
|
1900
1890
|
return getTempNode()
|
|
1901
1891
|
}
|
|
1902
1892
|
|
|
1903
1893
|
function processShow (el, options, root) {
|
|
1904
|
-
// 开启 virtualhost 全部走 props 传递处理
|
|
1905
|
-
// 未开启 virtualhost 直接绑定 display:none 到节点上
|
|
1906
1894
|
let show = getAndRemoveAttr(el, config[mode].directive.show).val
|
|
1907
1895
|
if (mode === 'swan') show = wrapMustache(show)
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
}
|
|
1896
|
+
let processFlag = el.parent === root
|
|
1897
|
+
// 当ali且未开启virtualHost时,mpxShow打到根节点上
|
|
1898
|
+
if (mode === 'ali' && !options.hasVirtualHost) processFlag = el === root
|
|
1899
|
+
if (options.isComponent && processFlag && isRealNode(el)) {
|
|
1900
|
+
if (show !== undefined) {
|
|
1901
|
+
show = `{{${parseMustache(show).result}&&mpxShow}}`
|
|
1902
|
+
} else {
|
|
1903
|
+
show = '{{mpxShow}}'
|
|
1916
1904
|
}
|
|
1917
|
-
|
|
1905
|
+
}
|
|
1906
|
+
if (show !== undefined) {
|
|
1907
|
+
if (isComponentNode(el, options)) {
|
|
1918
1908
|
if (show === '') {
|
|
1919
1909
|
show = '{{false}}'
|
|
1920
1910
|
}
|
|
@@ -1923,14 +1913,6 @@ function processShow (el, options, root) {
|
|
|
1923
1913
|
value: show
|
|
1924
1914
|
}])
|
|
1925
1915
|
} else {
|
|
1926
|
-
processShowStyle()
|
|
1927
|
-
}
|
|
1928
|
-
} else {
|
|
1929
|
-
processShowStyle()
|
|
1930
|
-
}
|
|
1931
|
-
|
|
1932
|
-
function processShowStyle () {
|
|
1933
|
-
if (show !== undefined) {
|
|
1934
1916
|
const showExp = parseMustache(show).result
|
|
1935
1917
|
let oldStyle = getAndRemoveAttr(el, 'style').val
|
|
1936
1918
|
oldStyle = oldStyle ? oldStyle + ';' : ''
|
|
@@ -2112,6 +2094,11 @@ function processElement (el, root, options, meta) {
|
|
|
2112
2094
|
processShow(el, options, root)
|
|
2113
2095
|
}
|
|
2114
2096
|
|
|
2097
|
+
if (transAli) {
|
|
2098
|
+
processAliStyleClassHack(el, options, root)
|
|
2099
|
+
processAliEventHack(el, options, root)
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2115
2102
|
if (!pass) {
|
|
2116
2103
|
processBindEvent(el, options)
|
|
2117
2104
|
processComponentIs(el, options)
|
|
@@ -2120,7 +2107,7 @@ function processElement (el, root, options, meta) {
|
|
|
2120
2107
|
processAttrs(el, options)
|
|
2121
2108
|
}
|
|
2122
2109
|
|
|
2123
|
-
function closeElement (el, meta
|
|
2110
|
+
function closeElement (el, meta) {
|
|
2124
2111
|
postProcessAtMode(el)
|
|
2125
2112
|
if (mode === 'web') {
|
|
2126
2113
|
postProcessWxs(el, meta)
|
|
@@ -2130,13 +2117,8 @@ function closeElement (el, meta, options) {
|
|
|
2130
2117
|
}
|
|
2131
2118
|
const pass = isNative || postProcessTemplate(el) || processingTemplate
|
|
2132
2119
|
postProcessWxs(el, meta)
|
|
2133
|
-
|
|
2134
2120
|
if (!pass) {
|
|
2135
|
-
|
|
2136
|
-
el = processAliAddComponentRootView(el, options)
|
|
2137
|
-
} else {
|
|
2138
|
-
el = postProcessComponentIs(el)
|
|
2139
|
-
}
|
|
2121
|
+
el = postProcessComponentIs(el)
|
|
2140
2122
|
}
|
|
2141
2123
|
postProcessFor(el)
|
|
2142
2124
|
postProcessIf(el)
|
|
@@ -59,7 +59,8 @@ 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)
|
|
62
|
+
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules),
|
|
63
|
+
proxyComponentEventsRules: mpx.proxyComponentEventsRules
|
|
63
64
|
})
|
|
64
65
|
|
|
65
66
|
if (meta.wxsContentMap) {
|
package/lib/wxs/loader.js
CHANGED
|
@@ -2,6 +2,7 @@ const NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin')
|
|
|
2
2
|
const EntryPlugin = require('webpack/lib/EntryPlugin')
|
|
3
3
|
const LazySet = require('webpack/lib/util/LazySet')
|
|
4
4
|
const LimitChunkCountPlugin = require('webpack/lib/optimize/LimitChunkCountPlugin')
|
|
5
|
+
const FlagEntryExportAsUsedPlugin = require('webpack/lib/FlagEntryExportAsUsedPlugin')
|
|
5
6
|
const path = require('path')
|
|
6
7
|
const WxsPlugin = require('./WxsPlugin')
|
|
7
8
|
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
@@ -81,7 +82,8 @@ module.exports.pitch = function (remainingRequest) {
|
|
|
81
82
|
new WxsPlugin({ mode }),
|
|
82
83
|
new NodeTargetPlugin(),
|
|
83
84
|
new EntryPlugin(this.context, request, { name: getName(filename) }),
|
|
84
|
-
new LimitChunkCountPlugin({ maxChunks: 1 })
|
|
85
|
+
new LimitChunkCountPlugin({ maxChunks: 1 }),
|
|
86
|
+
new FlagEntryExportAsUsedPlugin(true, 'entry')
|
|
85
87
|
]
|
|
86
88
|
|
|
87
89
|
const childCompiler = this._compilation.createChildCompiler(resourcePath, outputOptions, plugins)
|
package/lib/wxs/pre-loader.js
CHANGED
|
@@ -44,6 +44,15 @@ module.exports = function (content) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
+
CallExpression (path) {
|
|
48
|
+
const callee = path.node.callee
|
|
49
|
+
if (t.isIdentifier(callee) && callee.name === 'getRegExp') {
|
|
50
|
+
const argPath = path.get('arguments')[0]
|
|
51
|
+
if (argPath.isStringLiteral()) {
|
|
52
|
+
argPath.replaceWith(t.stringLiteral(argPath.node.extra.raw.slice(1, -1)))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
47
56
|
ForStatement (path) {
|
|
48
57
|
if (path.shouldStopTraverse) {
|
|
49
58
|
path.stop()
|
|
@@ -92,12 +101,19 @@ module.exports = function (content) {
|
|
|
92
101
|
},
|
|
93
102
|
CallExpression (path) {
|
|
94
103
|
const callee = path.node.callee
|
|
104
|
+
const args = path.node.arguments
|
|
95
105
|
const transMap = {
|
|
96
106
|
getDate: 'Date',
|
|
97
107
|
getRegExp: 'RegExp'
|
|
98
108
|
}
|
|
99
109
|
if (t.isIdentifier(callee) && transMap[callee.name]) {
|
|
100
|
-
|
|
110
|
+
if (callee.name === 'getRegExp') {
|
|
111
|
+
const arg = args[0]
|
|
112
|
+
if (t.isStringLiteral(arg)) {
|
|
113
|
+
args[0] = t.stringLiteral(arg.extra.raw.slice(1, -1))
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
path.replaceWith(t.newExpression(t.identifier(transMap[callee.name]), args))
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.38",
|
|
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": "29b5f9c3bad966c5ed2d3d16f49e6bcef55a0213"
|
|
84
84
|
}
|