@mpxjs/webpack-plugin 2.10.7-beta.9 → 2.10.8

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.
Files changed (42) hide show
  1. package/LICENSE +433 -0
  2. package/lib/dependencies/RequireExternalDependency.js +61 -0
  3. package/lib/file-loader.js +3 -2
  4. package/lib/index.js +60 -15
  5. package/lib/json-compiler/index.js +1 -0
  6. package/lib/parser.js +1 -1
  7. package/lib/platform/json/wx/index.js +43 -25
  8. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  9. package/lib/platform/template/wx/component-config/movable-view.js +10 -1
  10. package/lib/platform/template/wx/index.js +2 -1
  11. package/lib/react/LoadAsyncChunkModule.js +74 -0
  12. package/lib/react/index.js +3 -1
  13. package/lib/react/processJSON.js +74 -13
  14. package/lib/react/processScript.js +6 -6
  15. package/lib/react/script-helper.js +100 -41
  16. package/lib/runtime/components/react/context.ts +2 -12
  17. package/lib/runtime/components/react/dist/context.js +1 -1
  18. package/lib/runtime/components/react/dist/getInnerListeners.js +1 -1
  19. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +135 -0
  20. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +9 -63
  21. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +58 -301
  22. package/lib/runtime/components/react/dist/mpx-swiper.jsx +27 -53
  23. package/lib/runtime/components/react/dist/mpx-web-view.jsx +14 -28
  24. package/lib/runtime/components/react/dist/useAnimationHooks.js +2 -87
  25. package/lib/runtime/components/react/getInnerListeners.ts +1 -1
  26. package/lib/runtime/components/react/mpx-async-suspense.tsx +180 -0
  27. package/lib/runtime/components/react/mpx-movable-area.tsx +11 -98
  28. package/lib/runtime/components/react/mpx-movable-view.tsx +60 -350
  29. package/lib/runtime/components/react/mpx-swiper.tsx +25 -53
  30. package/lib/runtime/components/react/mpx-web-view.tsx +13 -33
  31. package/lib/runtime/components/react/types/global.d.ts +15 -0
  32. package/lib/runtime/components/react/useAnimationHooks.ts +2 -85
  33. package/lib/runtime/optionProcessorReact.d.ts +18 -0
  34. package/lib/runtime/optionProcessorReact.js +30 -0
  35. package/lib/script-setup-compiler/index.js +27 -5
  36. package/lib/template-compiler/compiler.js +4 -3
  37. package/lib/utils/dom-tag-config.js +17 -3
  38. package/lib/utils/trans-async-sub-rules.js +19 -0
  39. package/lib/web/script-helper.js +1 -1
  40. package/package.json +4 -4
  41. package/lib/runtime/components/react/AsyncContainer.tsx +0 -189
  42. package/lib/runtime/components/react/dist/AsyncContainer.jsx +0 -141
@@ -1,189 +0,0 @@
1
- import { ComponentType, ReactNode, Component, Fragment, Suspense } from 'react'
2
- import { View, Text, Image, StyleSheet, TouchableOpacity } from 'react-native'
3
- import FastImage from '@d11/react-native-fast-image'
4
-
5
- const styles = StyleSheet.create({
6
- container: {
7
- flex: 1,
8
- padding: 20,
9
- backgroundColor: '#fff'
10
- },
11
- loadingImage: {
12
- width: 100,
13
- height: 100,
14
- marginTop: 220,
15
- alignSelf: 'center'
16
- },
17
- buttonText: {
18
- color: '#fff',
19
- fontSize: 16,
20
- fontWeight: '500',
21
- textAlign: 'center'
22
- },
23
- errorImage: {
24
- marginTop: 80,
25
- width: 220,
26
- aspectRatio: 1,
27
- alignSelf: 'center'
28
- },
29
- errorText: {
30
- fontSize: 16,
31
- textAlign: 'center',
32
- color: '#333',
33
- marginBottom: 20
34
- },
35
- retryButton: {
36
- position: 'absolute',
37
- bottom: 54,
38
- left: 20,
39
- right: 20,
40
- backgroundColor: '#fff',
41
- paddingVertical: 15,
42
- borderRadius: 30,
43
- marginTop: 40,
44
- borderWidth: 1,
45
- borderColor: '#FF5F00'
46
- },
47
- retryButtonText: {
48
- color: '#FF5F00',
49
- fontSize: 16,
50
- fontWeight: '500',
51
- textAlign: 'center'
52
- }
53
- })
54
-
55
- type AsyncType = 'page' | 'component'
56
-
57
- interface PropsType<T extends AsyncType> {
58
- type: T
59
- props: object
60
- loading: ComponentType<unknown>
61
- fallback: ComponentType<unknown>
62
- children: (props: unknown) => ReactNode
63
- }
64
-
65
- interface StateType {
66
- hasError: boolean,
67
- key: number
68
- }
69
-
70
- interface ComponentError extends Error {
71
- request?: string
72
- type: 'timeout' | 'fail'
73
- }
74
-
75
- const DefaultLoading = () => {
76
- return (
77
- <View style={styles.container}>
78
- <FastImage
79
- style={styles.loadingImage}
80
- source={{ uri: 'https://dpubstatic.udache.com/static/dpubimg/439jiCVOtNOnEv9F2LaDs_loading.gif' }}
81
- resizeMode={FastImage.resizeMode.contain}></FastImage>
82
- </View>
83
- )
84
- }
85
-
86
- interface DefaultFallbackProps {
87
- onReload: () => void
88
- }
89
-
90
- const DefaultFallback = ({ onReload }: DefaultFallbackProps) => {
91
- return (
92
- <View style={styles.container}>
93
- <Image
94
- source={{ uri: 'https://dpubstatic.udache.com/static/dpubimg/Vak5mZvezPpKV5ZJI6P9b_drn-fallbak.png' }}
95
- style={styles.errorImage}
96
- resizeMode="contain"
97
- />
98
- <Text style={styles.errorText}>网络出了点问题,请查看网络环境</Text>
99
- <TouchableOpacity
100
- style={styles.retryButton}
101
- onPress={onReload}
102
- activeOpacity={0.7}
103
- >
104
- <Text style={styles.retryButtonText}>点击重试</Text>
105
- </TouchableOpacity>
106
- </View>
107
- )
108
- }
109
-
110
- export default class AsyncContainer extends Component<PropsType<AsyncType>, StateType> {
111
- private suspenseFallback: ReactNode
112
- private errorFallback: ReactNode
113
-
114
- constructor (props: PropsType<AsyncType>) {
115
- super(props)
116
- this.state = {
117
- hasError: false,
118
- key: 0
119
- }
120
- this.suspenseFallback = this.getSuspenseFallback()
121
- this.errorFallback = this.getErrorFallback()
122
- }
123
-
124
- // render 阶段收集到的错误
125
- static getDerivedStateFromError (error: ComponentError): StateType | undefined {
126
- if (error.name === 'ChunkLoadError') {
127
- return {
128
- hasError: true,
129
- key: 0
130
- }
131
- } else {
132
- // 被外层捕获
133
- throw error
134
- }
135
- }
136
-
137
- componentDidCatch (error: ComponentError): void {
138
- if (error.name === 'ChunkLoadError' && this.props.type === 'component') {
139
- const request = error.request || ''
140
- const subpackage = request.split('/').filter((i: string) => !!i)[0]
141
- global.onLazyLoadError({
142
- type: 'subpackage',
143
- subpackage: [subpackage],
144
- errMsg: `loadSubpackage: ${error.type}`
145
- })
146
- }
147
- }
148
-
149
- reloadPage () {
150
- this.setState((prevState) => {
151
- return {
152
- hasError: false,
153
- key: prevState.key + 1
154
- }
155
- })
156
- }
157
-
158
- getSuspenseFallback () {
159
- if (this.props.type === 'page') {
160
- const Fallback = this.props.loading || DefaultLoading
161
- return <Fallback />
162
- } else {
163
- const Fallback = this.props.loading
164
- return <Fallback {...this.props.props}></Fallback>
165
- }
166
- }
167
-
168
- getErrorFallback () {
169
- if (this.props.type === 'page') {
170
- const Fallback = this.props.fallback as ComponentType<DefaultFallbackProps> || DefaultFallback
171
- return <Fallback onReload={this.reloadPage.bind(this)}></Fallback>
172
- } else {
173
- const Fallback = this.props.loading
174
- return <Fallback {...this.props.props}></Fallback>
175
- }
176
- }
177
-
178
- render () {
179
- if (this.state.hasError) {
180
- return this.errorFallback
181
- } else {
182
- return (
183
- <Suspense fallback={this.suspenseFallback} key={this.state.key}>
184
- {this.props.children(this.props.props)}
185
- </Suspense>
186
- )
187
- }
188
- }
189
- }
@@ -1,141 +0,0 @@
1
- import { Component, Suspense } from 'react';
2
- import { View, Text, Image, StyleSheet, TouchableOpacity } from 'react-native';
3
- import FastImage from '@d11/react-native-fast-image';
4
- const styles = StyleSheet.create({
5
- container: {
6
- flex: 1,
7
- padding: 20,
8
- backgroundColor: '#fff'
9
- },
10
- loadingImage: {
11
- width: 100,
12
- height: 100,
13
- marginTop: 220,
14
- alignSelf: 'center'
15
- },
16
- buttonText: {
17
- color: '#fff',
18
- fontSize: 16,
19
- fontWeight: '500',
20
- textAlign: 'center'
21
- },
22
- errorImage: {
23
- marginTop: 80,
24
- width: 220,
25
- aspectRatio: 1,
26
- alignSelf: 'center'
27
- },
28
- errorText: {
29
- fontSize: 16,
30
- textAlign: 'center',
31
- color: '#333',
32
- marginBottom: 20
33
- },
34
- retryButton: {
35
- position: 'absolute',
36
- bottom: 54,
37
- left: 20,
38
- right: 20,
39
- backgroundColor: '#fff',
40
- paddingVertical: 15,
41
- borderRadius: 30,
42
- marginTop: 40,
43
- borderWidth: 1,
44
- borderColor: '#FF5F00'
45
- },
46
- retryButtonText: {
47
- color: '#FF5F00',
48
- fontSize: 16,
49
- fontWeight: '500',
50
- textAlign: 'center'
51
- }
52
- });
53
- const DefaultLoading = () => {
54
- return (<View style={styles.container}>
55
- <FastImage style={styles.loadingImage} source={{ uri: 'https://dpubstatic.udache.com/static/dpubimg/439jiCVOtNOnEv9F2LaDs_loading.gif' }} resizeMode={FastImage.resizeMode.contain}></FastImage>
56
- </View>);
57
- };
58
- const DefaultFallback = ({ onReload }) => {
59
- return (<View style={styles.container}>
60
- <Image source={{ uri: 'https://dpubstatic.udache.com/static/dpubimg/Vak5mZvezPpKV5ZJI6P9b_drn-fallbak.png' }} style={styles.errorImage} resizeMode="contain"/>
61
- <Text style={styles.errorText}>网络出了点问题,请查看网络环境</Text>
62
- <TouchableOpacity style={styles.retryButton} onPress={onReload} activeOpacity={0.7}>
63
- <Text style={styles.retryButtonText}>点击重试</Text>
64
- </TouchableOpacity>
65
- </View>);
66
- };
67
- export default class AsyncContainer extends Component {
68
- suspenseFallback;
69
- errorFallback;
70
- constructor(props) {
71
- super(props);
72
- this.state = {
73
- hasError: false,
74
- key: 0
75
- };
76
- this.suspenseFallback = this.getSuspenseFallback();
77
- this.errorFallback = this.getErrorFallback();
78
- }
79
- // render 阶段收集到的错误
80
- static getDerivedStateFromError(error) {
81
- if (error.name === 'ChunkLoadError') {
82
- return {
83
- hasError: true,
84
- key: 0
85
- };
86
- }
87
- else {
88
- // 被外层捕获
89
- throw error;
90
- }
91
- }
92
- componentDidCatch(error) {
93
- if (error.name === 'ChunkLoadError' && this.props.type === 'component') {
94
- const request = error.request || '';
95
- const subpackage = request.split('/').filter((i) => !!i)[0];
96
- global.onLazyLoadError({
97
- type: 'subpackage',
98
- subpackage: [subpackage],
99
- errMsg: `loadSubpackage: ${error.type}`
100
- });
101
- }
102
- }
103
- reloadPage() {
104
- this.setState((prevState) => {
105
- return {
106
- hasError: false,
107
- key: prevState.key + 1
108
- };
109
- });
110
- }
111
- getSuspenseFallback() {
112
- if (this.props.type === 'page') {
113
- const Fallback = this.props.loading || DefaultLoading;
114
- return <Fallback />;
115
- }
116
- else {
117
- const Fallback = this.props.loading;
118
- return <Fallback {...this.props.props}></Fallback>;
119
- }
120
- }
121
- getErrorFallback() {
122
- if (this.props.type === 'page') {
123
- const Fallback = this.props.fallback || DefaultFallback;
124
- return <Fallback onReload={this.reloadPage.bind(this)}></Fallback>;
125
- }
126
- else {
127
- const Fallback = this.props.loading;
128
- return <Fallback {...this.props.props}></Fallback>;
129
- }
130
- }
131
- render() {
132
- if (this.state.hasError) {
133
- return this.errorFallback;
134
- }
135
- else {
136
- return (<Suspense fallback={this.suspenseFallback} key={this.state.key}>
137
- {this.props.children(this.props.props)}
138
- </Suspense>);
139
- }
140
- }
141
- }