Skip to content

Commit 19741c3

Browse files
committed
feat: moduleLoader error handle
affects: @vue-async/module-loader $moduleLoader 格式变更和支持 Promise回调或success方法回调 异常处理自定义 模块名称自动查找
1 parent 4688a2d commit 19741c3

34 files changed

+2233
-2250
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"@typescript-eslint/parser": "^2.12.0",
4545
"@zerollup/ts-transform-paths": "^1.7.18",
4646
"babel-eslint": "^10.1.0",
47-
"babel-jest": "^24.9.0",
4847
"child_process": "^1.0.2",
4948
"commitizen": "^4.0.3",
5049
"concurrently": "^5.1.0",

packages/module-loader/dev/App.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ export default Vue.extend({
1919
{ staticStyle: { margin: '0 10px 5px', display: 'block' }, props: { to: { name: 'remote-component-b' } } },
2020
'Remote Component B as router component',
2121
),
22+
h(
23+
'router-link',
24+
{ staticStyle: { margin: '0 10px 5px', display: 'block' }, props: { to: { name: 'wrong-component-name' } } },
25+
'setted wrong component name',
26+
),
27+
h(
28+
'router-link',
29+
{ staticStyle: { margin: '0 10px 5px', display: 'block' }, props: { to: { name: 'wrong-component-entry' } } },
30+
'setted wrong component entry',
31+
),
2232
h('router-view'),
2333
]);
2434
},

packages/module-loader/dev/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<script src="//cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js"></script>
1919
<script src="//cdn.jsdelivr.net/npm/vue-router@3.3.4/dist/vue-router.min.js"></script>
2020
<script src="//cdn.jsdelivr.net/npm/vuex@3.5.1/dist/vuex.min.js"></script>
21-
<script src="/static/utils.min.js"></script>
21+
<script src="//cdn.jsdelivr.net/npm/@vue-async/utils@1.0.5/dist/utils.min.js"></script>
2222
<script src="/module-loader.js"></script>
2323
</body>
2424

packages/module-loader/dev/main.ts

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Vue from 'vue';
1+
// import Vue from 'vue';
22
import router, { addRoutes, lazyLoadView } from './router';
33
import store from './store';
44
import ModuleLoader from '@vue-async/module-loader';
@@ -28,21 +28,65 @@ addRoutes([
2828
name: 'remote-component-b',
2929
component: () => lazyLoadView(app.$componentLoader('componentB', '/static/componentB/componentB.umd.min.js')),
3030
},
31+
{
32+
path: 'wrong-component-name',
33+
name: 'wrong-component-name',
34+
component: () =>
35+
lazyLoadView(app.$componentLoader('wrongComponentName', '/static/componentB/componentB.umd.min.js')),
36+
},
37+
{
38+
path: 'wrong-component-entry',
39+
name: 'wrong-component-entry',
40+
component: () =>
41+
lazyLoadView(app.$componentLoader('entry', 'http://www.xx.com/static/componentB/errorComponent.umd.min.js')),
42+
},
3143
]);
3244

3345
app
34-
.$moduleLoader({
35-
dymanicRouter: '/static/dymanicRouter/dymanicRouter.umd.min.js',
36-
// page 异步加载,样式限 page load 加载出来
37-
// dymanicRouter: {
38-
// entry: '/static/dymanicRouter/dymanicRouter.umd.min.js',
39-
// css: ['/static/dymanicRouter/css/1.281753bd.css', '/static/dymanicRouter/css/2.2b65cb29.css'],
40-
// },
41-
dymanicComponent: {
42-
entry: '/static/dymanicComponent/dymanicComponent.umd.min.js',
43-
css: '/static/dymanicComponent/dymanicComponent.css',
46+
.$moduleLoader(
47+
[
48+
{
49+
dymanicRouter: '/static/dymanicRouter/dymanicRouter.umd.js',
50+
// page 异步加载,样式限 page load 加载出来
51+
// dymanicRouter: {
52+
// entry: '/static/dymanicRouter/dymanicRouter.umd.min.js',
53+
// css: ['/static/dymanicRouter/css/1.281753bd.css', '/static/dymanicRouter/css/2.2b65cb29.css'],
54+
// },
55+
dymanicComponent: {
56+
entry: '/static/dymanicComponent/dymanicComponent.umd.min.js',
57+
styles: '/static/dymanicComponent/dymanicComponent.css',
58+
},
59+
},
60+
{
61+
// 同名
62+
moduleName: 'dymanicComponent',
63+
entry: '/static/dymanicComponentCopy/dymanicComponent.umd.min.js',
64+
styles: '/static/dymanicComponentCopy/dymanicComponent.css',
65+
},
66+
{
67+
// 错误 module name (执行正常)
68+
moduleName: 'wrongName',
69+
entry: '/static/dymanicComponentCopy/dymanicComponent.umd.min.js',
70+
},
71+
{
72+
// 错误 entry (执行 error)
73+
moduleName: 'wrongEntry',
74+
entry: 'http://www.xx.com/error.umd.min.js',
75+
},
76+
// fn
77+
// (Vue: any) => {
78+
// console.log(Vue);
79+
// },
80+
],
81+
{
82+
success: () => {
83+
app.$mount('#app');
84+
},
85+
error(msg, module) {
86+
console.warn(msg, module);
87+
},
4488
},
45-
})
89+
)
4690
.then(() => {
47-
app.$mount('#app');
91+
// then won't exec when success is set in options
4892
});

0 commit comments

Comments
 (0)