Skip to content

Commit c1722fa

Browse files
committed
perf: ts baseUrl 修改
affects: @vue-async/module-loader, @vue-async/resource-manager, @vue-async/utils
1 parent 56bdd68 commit c1722fa

File tree

18 files changed

+279
-90
lines changed

18 files changed

+279
-90
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"useWorkspaces": true,
55
"command": {
66
"publish": {
7-
"conventionalCommits": false,
7+
"conventionalCommits": true,
88
"gitTagVersion": false,
99
"gitReset": false,
1010
"allowBranch": ["master"],

packages/module-loader/dev/plugins/module-loader.ts

Lines changed: 84 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* eslint-disable no-console */
22
import Vue from 'vue';
33
import VueRouter, { RouteConfig } from 'vue-router';
4-
import ModuleLoader from '@vue-async/module-loader';
4+
import ModuleLoader, { Modules } from '@vue-async/module-loader';
55
import { root, megreRoutes, lazyLoadView } from '../router/utils';
66

7-
Vue.use(ModuleLoader);
8-
97
// Types
108
import { Plugin } from '@nuxt/types';
119

10+
Vue.use(ModuleLoader);
11+
1212
const plugin: Plugin = async (cxt) => {
1313
const { app, store } = cxt;
1414

@@ -76,56 +76,90 @@ const plugin: Plugin = async (cxt) => {
7676
addRoutes,
7777
}).registerDynamicComponent(store);
7878

79-
await moduleLoader
80-
.load(
81-
[
82-
{
83-
// page 异步加载,样式限 page load 加载出来
84-
dymanicRouter: {
85-
entry: 'http://localhost:7001/modules/dymanicRouter/dymanicRouter.umd.js',
86-
// css: ['http://localhost:7001/modules/dymanicRouter/css/1.281753bd.css', 'http://localhost:7001/modules/dymanicRouter/css/2.2b65cb29.css'],
87-
args: {
88-
addRoutes,
89-
},
90-
},
91-
dymanicComponent: {
92-
entry: 'http://localhost:7001/modules/dymanicComponent/dymanicComponent.umd.js',
93-
styles: 'http://localhost:7001/modules/dymanicComponent/dymanicComponent.css',
94-
},
95-
sortTest: 'http://localhost:7001/modules/sortTest/sortTest.umd.js',
96-
},
97-
{
98-
// 同名
99-
moduleName: 'dymanicComponent',
100-
entry: 'http://localhost:7001/modules/dymanicComponentCopy/dymanicComponent.umd.js',
101-
styles: 'http://localhost:7001/modules/dymanicComponentCopy/dymanicComponent.css',
102-
},
103-
{
104-
// 错误 module name (执行正常, 但不能跟在相同 entry 后面执行, 会找不到模块)
105-
moduleName: 'wrongName',
106-
entry: 'http://localhost:7001/modules/dymanicComponentCopy/dymanicComponent.umd.js',
79+
let modules: Modules = [];
80+
if (process.client) {
81+
// modules = [
82+
// {
83+
// // page 异步加载,样式限 page load 加载出来
84+
// dymanicRouter: {
85+
// entry: 'http://localhost:7001/modules/dymanicRouter/dymanicRouter.umd.js',
86+
// // css: ['http://localhost:7001/modules/dymanicRouter/css/1.281753bd.css', 'http://localhost:7001/modules/dymanicRouter/css/2.2b65cb29.css'],
87+
// args: {
88+
// addRoutes,
89+
// },
90+
// },
91+
// dymanicComponent: {
92+
// entry: 'http://localhost:7001/modules/dymanicComponent/dymanicComponent.umd.js',
93+
// styles: 'http://localhost:7001/modules/dymanicComponent/dymanicComponent.css',
94+
// },
95+
// sortTest: 'http://localhost:7001/modules/sortTest/sortTest.umd.js',
96+
// },
97+
// {
98+
// // 同名
99+
// moduleName: 'dymanicComponent',
100+
// entry: 'http://localhost:7001/modules/dymanicComponentCopy/dymanicComponent.umd.js',
101+
// styles: 'http://localhost:7001/modules/dymanicComponentCopy/dymanicComponent.css',
102+
// },
103+
// {
104+
// // 错误 module name (执行正常, 但不能跟在相同 entry 后面执行, 会找不到模块)
105+
// moduleName: 'wrongName',
106+
// entry: 'http://localhost:7001/modules/dymanicComponentCopy/dymanicComponent.umd.js',
107+
// },
108+
// {
109+
// // 错误 entry (执行 error)
110+
// moduleName: 'wrongEntry',
111+
// entry: 'http://www.xx.com/error.umd.js',
112+
// },
113+
// // function module
114+
// (_Vue: any) => {
115+
// console.log('[dev] function module');
116+
// },
117+
// ];
118+
modules = {
119+
// page 异步加载,样式限 page load 加载出来
120+
dymanicRouter: {
121+
entry: 'http://localhost:7001/modules/dymanicRouter/dymanicRouter.umd.js',
122+
// css: ['http://localhost:7001/modules/dymanicRouter/css/1.281753bd.css', 'http://localhost:7001/modules/dymanicRouter/css/2.2b65cb29.css'],
123+
args: {
124+
addRoutes,
107125
},
108-
{
109-
// 错误 entry (执行 error)
110-
moduleName: 'wrongEntry',
111-
entry: 'http://www.xx.com/error.umd.js',
112-
},
113-
// function module
114-
(_Vue: any) => {
115-
console.log('[dev] function module');
116-
},
117-
],
118-
{
119-
sync: true,
120-
// success: () => {
121-
// // app.$mount('#app');
122-
// },
123-
error(msg: string, module: any) {
124-
// eslint-disable-next-line no-console
125-
console.warn(`[dev] ${msg}`, module);
126+
},
127+
// dymanicComponent: {
128+
// entry: 'http://localhost:7001/modules/dymanicComponent/dymanicComponent.umd.js',
129+
// styles: 'http://localhost:7001/modules/dymanicComponent/dymanicComponent.css',
130+
// },
131+
// sortTest: 'http://localhost:7001/modules/sortTest/sortTest.umd.js',
132+
};
133+
} else {
134+
modules = {
135+
// page 异步加载,样式限 page load 加载出来
136+
dymanicRouter: {
137+
entry:
138+
'/Users/hubertx/Desktop/Workspace/projects/vue-async/packages/module-loader/dev-modules/dymanicRouter/dymanicRouter.umd.js',
139+
// css: ['http://localhost:7001/modules/dymanicRouter/css/1.281753bd.css', 'http://localhost:7001/modules/dymanicRouter/css/2.2b65cb29.css'],
140+
args: {
141+
addRoutes,
126142
},
127143
},
128-
)
144+
// dymanicComponent: {
145+
// entry: '../../dev-modules/dymanicComponent/dymanicComponent.umd.js',
146+
// styles: 'http://localhost:7001/modules/dymanicComponent/dymanicComponent.css',
147+
// },
148+
// sortTest: '../../dev-modules/sortTest/sortTest.umd.js',
149+
};
150+
}
151+
152+
await moduleLoader
153+
.load(modules, {
154+
sync: true,
155+
// success: () => {
156+
// // app.$mount('#app');
157+
// },
158+
error(msg: string, module: any) {
159+
// eslint-disable-next-line no-console
160+
console.warn(`[dev] ${msg}`, module);
161+
},
162+
})
129163
.then(() => {
130164
// then won't exec when success set up
131165
});

packages/module-loader/src/ability/dynamicComponent/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/**
22
* dynamicComponent
33
*/
4+
import { error } from '@vue-async/utils';
5+
6+
// Types
47
import { VueConstructor } from 'vue';
58
import { Store } from 'vuex';
6-
import { error } from '@vue-async/utils';
7-
import { DynamicComponent } from '../../../types';
9+
import { DynamicComponent } from 'types/module';
810

911
export const namespaces = 'dynamicComponent';
1012

packages/module-loader/src/ability/dynamicComponent/storeModule.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { getComponentName, error } from '@vue-async/utils';
2-
import { DynamicComponent } from '../../../types';
2+
3+
// Types
4+
import { DynamicComponent } from 'types/module';
35

46
export type State = {
57
GLOBAL: { [componentName: string]: DynamicComponent };

packages/module-loader/src/ability/moduleLoader.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/**
22
* moduleLoader
33
*/
4-
import { VueConstructor } from 'vue';
4+
55
import { error as globalError, warn as globalWarn, isPlainObject, isFunction } from '@vue-async/utils';
6-
import vm from 'vm';
6+
77
import * as spa from '../utils/spa';
88

99
// Types
10-
import { Modules, ModuleData, ModuleRemoteConfig, ModuleLoaderOption } from '../../types';
10+
import { VueConstructor } from 'vue';
11+
import { Context as vmContext } from 'vm';
12+
import { Modules, ModuleData, ModuleRemoteConfig, ModuleLoaderOption } from 'types/module';
1113

1214
interface MutableRefObject<T> {
1315
current: T;
@@ -78,11 +80,7 @@ function validateExportLifecycle(exports: any) {
7880
}
7981

8082
/** 获取生命周期对象 */
81-
function getLifecyclesFromExports(
82-
scriptExports: any,
83-
moduleName: string,
84-
global: WindowProxy | vm.Context,
85-
): Lifecycles {
83+
function getLifecyclesFromExports(scriptExports: any, moduleName: string, global: WindowProxy | vmContext): Lifecycles {
8684
if (validateExportLifecycle(scriptExports)) {
8785
const _export = (scriptExports && scriptExports.default) || scriptExports;
8886
return isFunction(_export) ? { bootstrap: _export } : scriptExports;

packages/module-loader/src/framework.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { VueConstructor, Component as VueComponent, AsyncComponent } from 'vue';
21
import { RouteConfig } from 'vue-router';
32
import { error, warn, hasOwn, isPlainObject } from '@vue-async/utils';
4-
import { Framework, ModuleLoaderExtension } from '../types';
53
import install from './install';
64

5+
// Types
6+
import { VueConstructor, Component as VueComponent, AsyncComponent } from 'vue';
7+
import { Framework, ModuleLoaderExtension } from 'types/module';
8+
79
export default class ModuleLoader<T = Record<string, any>> {
810
static install = install;
911
static installed = false;

packages/module-loader/src/install.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { VueConstructor } from 'vue';
2-
import { Route, RawLocation } from 'vue-router';
31
import dynamicComponent, { namespaces as dynamicComponentPath } from './ability/dynamicComponent';
42
import dynamicComponentState from './ability/dynamicComponent/storeModule';
53
import createEventBus from './ability/eventBus';
64
import createModuleLoader from './ability/moduleLoader';
75
import createComponentLoader from './ability/componentLoader';
86
import ModuleLoader from './framework';
7+
8+
// Types
9+
import { VueConstructor } from 'vue';
910
import { Store } from 'vuex';
10-
import VueRouter from 'vue-router';
11+
import VueRouter, { Route, RawLocation } from 'vue-router';
1112

1213
export default function install(this: typeof ModuleLoader, Vue: VueConstructor) {
1314
if ((install as any).installed) return;
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"baseUrl": "src",
4+
"baseUrl": ".",
55
"outDir": "dist",
6-
"declaration": true,
7-
// "declarationDir": "types",
8-
// "paths": {},
96
"composite": true
107
},
11-
"include": ["src/**/*", "types", "test/sandbox/importEntry.spec.js"],
8+
"include": ["src", "types"],
129
"references": [{ "path": "../utils" }]
1310
}

packages/resource-manager/src/Suspense.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Vue, { CreateElement, VNode, VNodeChildren } from 'vue';
22
import { error } from '@vue-async/utils';
33
import { pushSuspenseInstance, popSuspenseInstance, currentSuspenseInstance } from './currentInstance';
4-
import { UseOptions, AsyncFactory } from '../types';
4+
5+
// Types
6+
import { UseOptions, AsyncFactory } from 'types/resource-mananger';
57

68
export const RESOLVED = 'resolved';
79
export const REJECTED = 'rejected';

packages/resource-manager/src/createResource.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { error } from '@vue-async/utils';
33
import { del, add } from './Suspense';
44
import { currentInstance, currentSuspenseInstance, setCurrentInstance } from './currentInstance';
55
import findSuspenseInstance from './findSuspenseInstance';
6-
import { AsyncFactory, ResourceOptions, ResourceResult } from '../types';
6+
7+
// Types
8+
import { AsyncFactory, ResourceOptions, ResourceResult } from 'types/resource-mananger';
79

810
Vue.mixin({
911
created(this: Vue) {

0 commit comments

Comments
 (0)