Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/didi/mpx
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki committed Nov 4, 2021
2 parents 94b2bdd + 0a29675 commit c1afce0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
17 changes: 17 additions & 0 deletions docs-vuepress/api/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,23 @@ new MpxWebpackPlugin({
- **参考**:[单元测试](../guide/tool/unit-test.md)
### autoVirtualHostRules
- **类型**:[`Rules`](#rules)
- **详细**:批量配置是否虚拟化组件节点,对应微信中[`VirtualHost`](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html) 。默认不开启,开启后也将抹平支付宝小程序中的表现差异。提供 include 和 exclude 以精确控制对哪些文件开启VirtualHost,哪些不开启。和webpack的rules规则相同。
- **背景**:默认情况下,自定义组件本身的那个节点是一个“普通”的节点,使用时可以在这个节点上设置 `class``style` 、动画、 flex 布局等,就如同普通的 view 组件节点一样。但有些时候,自定义组件并不希望这个节点本身可以设置样式、响应 flex 布局等,而是希望自定义组件内部的第一层节点能够响应 flex 布局或者样式由自定义组件本身完全决定。这种情况下,可以将这个自定义组件设置为“虚拟的”。
- **示例**:
```js
new MpxWebpackPlugin({
autoVirtualHostRules: {
include: [resolve('../src')],
exclude: [resolve('../components/other')]
}
})
```
##
## MpxWebpackPlugin static methods
`MpxWebpackPlugin` 通过静态方法暴露了以下五个内置 loader,详情如下:
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/platform/patch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getDefaultOptions as getWxDefaultOptions } from './wx/getDefaultOptions
import { getDefaultOptions as getAliDefaultOptions } from './ali/getDefaultOptions'
import { getDefaultOptions as getSwanDefaultOptions } from './swan/getDefaultOptions'
import { getDefaultOptions as getWebDefaultOptions } from './web/getDefaultOptions'
import { error } from '../../helper/log'

export default function createFactory (type) {
return (options, { isNative, customCtor, customCtorType } = {}) => {
Expand All @@ -23,6 +24,9 @@ export default function createFactory (type) {
if (global.currentCtorType === 'page') {
options.__pageCtor__ = true
}
if (global.currentResourceType && global.currentResourceType !== type) {
error(`The ${global.currentResourceType} [${global.currentResource}] is not supported to be created by ${type} constructor.`)
}
} else {
if (type === 'page') {
ctor = Page
Expand Down
17 changes: 17 additions & 0 deletions packages/webpack-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ try {
context.setTimeout = setTimeout;
context.JSON = JSON;
context.Math = Math;
context.Date = Date;
context.RegExp = RegExp;
context.Infinity = Infinity;
context.isFinite = isFinite;
Expand All @@ -964,6 +965,22 @@ try {
context.ArrayBuffer = ArrayBuffer;
context.Symbol = Symbol;
context.Reflect = Reflect;
context.Object = Object;
context.Error = Error;
context.Array = Array;
context.Float32Array = Float32Array;
context.Float64Array = Float64Array;
context.Int16Array = Int16Array;
context.Int32Array = Int32Array;
context.Int8Array = Int8Array;
context.Uint16Array = Uint16Array;
context.Uint32Array = Uint32Array;
context.Uint8ClampedArray = Uint8ClampedArray;
context.String = String;
context.Function = Function;
context.SyntaxError = SyntaxError;
context.decodeURIComponent = decodeURIComponent;
context.encodeURIComponent = encodeURIComponent;
}
} catch(e){
}\n`)
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-plugin/lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ module.exports = function (content) {
ctor = 'Component'
}
globalInjectCode += `global.currentCtor = ${ctor}\n`
globalInjectCode += `global.currentResourceType = '${ctorType}'\n`
globalInjectCode += `global.currentCtorType = ${JSON.stringify(ctor.replace(/^./, (match) => {
return match.toLowerCase()
}))}\n`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = function ({ print }) {
if (isMustache(value)) {
// 如果是个变量,报warning
baiduValueLog({ name, value })
} else if (supportList.indexOf(value) === -1) {
} else if (value && supportList.indexOf(value) === -1) {
baiduValueLogError({ name, value })
}
},
Expand All @@ -91,7 +91,7 @@ module.exports = function ({ print }) {
if (isMustache(value)) {
// 如果是个变量,报warning
qqValueLog({ name, value })
} else if (supportList.indexOf(value) === -1) {
} else if (value && supportList.indexOf(value) === -1) {
qqValueLogError({ name, value })
}
},
Expand All @@ -103,7 +103,7 @@ module.exports = function ({ print }) {
ttValueLog({ name, value })
} else {
const supportList = ['share', 'getPhoneNumber', 'contact']
if (supportList.indexOf(value) === -1) {
if (value && supportList.indexOf(value) === -1) {
ttValueLogError({ name, value })
}
}
Expand Down

0 comments on commit c1afce0

Please sign in to comment.