Skip to content

Commit 2ef0000

Browse files
authored
Merge pull request #2160 from didi/feat-compile-config-disablePageTransition
feat: 编译阶段支持disablePageTransition
2 parents 7c28c9b + b205327 commit 2ef0000

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

docs-vitepress/api/app-config.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ mpx.config.webRouteConfig = {
158158
```
159159

160160
## webConfig
161-
web 环境下的一些配置,如路由模式,页面切换动画效果等
161+
web 环境下的一些配置,如路由模式
162162

163163
- **用法**:
164164
```js
@@ -169,3 +169,4 @@ mpx.config.webConfig.routeConfig = {
169169
// 禁用页面切换动画
170170
mpx.config.webConfig.disablePageTransition = true
171171
```
172+
此处的 `disablePageTransition` 后续将被废弃,请使用编译阶段的[disablePageTransition](./compile.md#webconfig)进行配置

docs-vitepress/api/compile.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,10 @@ transRpxFn 配置用于自定义输出 web 时对于 rpx 样式单位的转换
828828

829829
useSSR 默认值为 `false`,当 SSR 模式下使用异步分包时,需要将 useSSR 设置为 `true`, 其他场景不需要。
830830

831+
`{disablePageTransition: boolean}`
832+
833+
用于配置禁用/开启页面切换动画,默认禁用
834+
831835

832836
```js
833837
// mpx.config.js
@@ -841,7 +845,9 @@ module.exports = defineConfig({
841845
return `${$1 * +(100 / 750).toFixed(8)}vw`
842846
},
843847
// 当 SSR 模式下使用异步分包时
844-
useSSR: true
848+
useSSR: true,
849+
// 开启页面切换动画
850+
disablePageTransition: false
845851
}
846852
}
847853
}

packages/webpack-plugin/lib/runtime/optionProcessor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export function processComponentOption (
1414
componentGenerics,
1515
genericsInfo,
1616
wxsMixin,
17-
hasApp
17+
hasApp,
18+
disablePageTransition
1819
}
1920
) {
2021
// 局部注册页面和组件中依赖的组件
@@ -79,7 +80,7 @@ registered in parent context!`)
7980
transitionName: ''
8081
}
8182
}
82-
if (!global.__mpx.config.webConfig.disablePageTransition) {
83+
if (!disablePageTransition) {
8384
option.watch = {
8485
$route: {
8586
handler () {

packages/webpack-plugin/lib/web/processScript.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ module.exports = function (script, {
2727
}, callback) {
2828
const { projectRoot, appInfo, webConfig, i18n } = loaderContext.getMpx()
2929

30+
const { disablePageTransition = true } = webConfig
31+
3032
let output = '/* script */\n'
3133

3234
let scriptSrcMode = srcMode
@@ -86,7 +88,8 @@ module.exports = function (script, {
8688
componentGenerics: ${JSON.stringify(componentGenerics)},
8789
genericsInfo: ${JSON.stringify(genericsInfo)},
8890
wxsMixin: getWxsMixin(wxsModules),
89-
hasApp: ${hasApp}
91+
hasApp: ${hasApp},
92+
disablePageTransition: ${JSON.stringify(disablePageTransition)},
9093
})\n`
9194
return content
9295
}

packages/webpack-plugin/lib/web/processTemplate.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ module.exports = function (template, {
3535
let output = '/* template */\n'
3636

3737
if (ctorType === 'app') {
38-
const { el } = webConfig
38+
const { el, disablePageTransition = true } = webConfig
3939
const idName = (el && el.match(/#(.*)/) && el.match(/#(.*)/)[1]) || 'app'
4040
template = {
4141
tag: 'template',
42-
content: `<div id="${idName}"><transition :name="transitionName"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></transition></div>`
42+
content: disablePageTransition
43+
? `<div id="${idName}"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></div>`
44+
: `<div id="${idName}"><transition :name="transitionName"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></transition></div>`
4345
}
4446
builtInComponentsMap['mpx-keep-alive'] = {
4547
resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', { isComponent: true })

0 commit comments

Comments
 (0)