Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过静态分析减小wxml大小 #77

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions fixtures/sizeRNvsMPvsAlita/src/CommonPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export default class CommonPage extends Component {
history.push('Page1')
}}
/>
<Button
title={"to Page2"}
onPress={() => {
history.push('Page2')
}}
/>
</View>

);
Expand Down
101 changes: 101 additions & 0 deletions fixtures/sizeRNvsMPvsAlita/src/Page2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React, { Component } from "react";
import { StyleSheet, Text, View, Platform } from "react-native"

/*
经过静态解析方式,以下代码由原来会生成以下6块代码段减少到0块
<template name="c">
<block wx:if="{{_t.l(d)}}">{{d}}</block>
<_g wx:elif="{{d._generic}}" diuu="{{d._generic}}" style="{{_t.s(d._genericstyle)}}"/>
<template wx:elif="{{d.tempName}}" is="{{d.tempName}}" data="{{...d}}"/>
<block wx:else>
<block wx:for="{{d}}" wx:key="key">
<block wx:if="{{_t.l(item)}}">{{item}}</block>
<_g wx:elif="{{item._generic}}" diuu="{{item._generic}}" style="{{_t.s(item._genericstyle)}}"/>
<template wx:else is="{{item.tempName}}" data="{{...item}}"/>
</block>
</block>
</template>
*/

const styles = StyleSheet.create({
container: {
textAlign: 'center',
paddingTop: 50
},
red: {
color: 'red',
fontSize: 20
},
blue: {
color: 'blue',
fontSize: 20
}
});


export default class Page2 extends Component {
a() {
return (
<View>
{this.b()}
</View>
)
}

b() {
return (
<View>
{this.c()}
</View>
)
}

c() {
return (
<View>
<Text style={styles.red}>
ccc
</Text>
</View>
)
}

render() {
const d = <View><Text style={styles.blue}>ddd</Text></View>
let e = null
e = <View><Text style={styles.red}>eee</Text></View>
const isTrue = true

return (
<View style={styles.container}>
<View>
{this.a()}
{this.c()}
<View>
<View>
{d}
{e}
<View>
{
isTrue && d
}
{
isTrue && this.c()
}
<View>
{
isTrue ? d : e
}
{
isTrue ? this.c() : e
}
</View>
</View>
</View>
</View>
</View>
</View>
);
}
}

2 changes: 2 additions & 0 deletions fixtures/sizeRNvsMPvsAlita/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React, {PureComponent} from 'react'
import {Router, Route, TabRouter} from '@areslabs/router'

import Page1 from './Page1'
import Page2 from './Page2'
import CommonPage from './CommonPage'

import {f1} from './util'
Expand Down Expand Up @@ -42,6 +43,7 @@ export default class App extends PureComponent {

{/*分包用来测试体积*/}
<Route subpage="one" key={"Page1"} component={Page1}/>
<Route subpage="two" key={"Page2"} component={Page2}/>
</Router>
)
}
Expand Down
Loading