Skip to content

Commit e35cfae

Browse files
author
hubert
committed
chore: move playground to root
1 parent 9f48082 commit e35cfae

File tree

19 files changed

+2487
-1733
lines changed

19 files changed

+2487
-1733
lines changed

mock-submodules/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@test/sub-modules",
2+
"name": "@mock/submodules",
33
"version": "0.1.3",
44
"private": true,
55
"license": "MIT",

mock-submodules/src/dymanicRouter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineBootstrap, defineMount } from '@vue-async/module-loader/esm/sub';
1+
import { defineBootstrap, defineMount } from '@vue-async/module-loader/sub';
22
// 模块的路由配置数组
33
import routes from './router';
44
import './assets/index.css';

mock-submodules/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"noImplicitAny": false,
1111
"jsx": "preserve",
1212
"paths": {
13-
"@vue-async/module-loader/esm/*": ["../packages/module-loader/src/*"]
13+
"@vue-async/module-loader/*": ["../packages/module-loader/src/*"]
1414
}
1515
},
1616
"include": ["src"]

mock-submodules/yarn.lock

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,29 @@ __metadata:
592592
languageName: node
593593
linkType: hard
594594

595+
"@mock/submodules@workspace:.":
596+
version: 0.0.0-use.local
597+
resolution: "@mock/submodules@workspace:."
598+
dependencies:
599+
"@vitejs/plugin-vue": ^5.0.4
600+
"@vitejs/plugin-vue-jsx": ^3.0.1
601+
"@vue/eslint-config-prettier": ^6.0.0
602+
"@vue/eslint-config-typescript": ^5.0.2
603+
concurrently: ^8.2.2
604+
core-js: ^3.6.4
605+
eslint-plugin-vue: ^5.0.0
606+
less: ^3.11.1
607+
less-loader: ^5.0.0
608+
lodash.merge: ^4.6.2
609+
rimraf: ^5.0.7
610+
stylus: ^0.54.5
611+
stylus-loader: ^3.0.2
612+
vite: ^5.1.6
613+
vue: ^3.0.0
614+
vue-demi: "*"
615+
languageName: unknown
616+
linkType: soft
617+
595618
"@npmcli/agent@npm:^2.0.0":
596619
version: 2.2.2
597620
resolution: "@npmcli/agent@npm:2.2.2"
@@ -733,29 +756,6 @@ __metadata:
733756
languageName: node
734757
linkType: hard
735758

736-
"@test/sub-modules@workspace:.":
737-
version: 0.0.0-use.local
738-
resolution: "@test/sub-modules@workspace:."
739-
dependencies:
740-
"@vitejs/plugin-vue": ^5.0.4
741-
"@vitejs/plugin-vue-jsx": ^3.0.1
742-
"@vue/eslint-config-prettier": ^6.0.0
743-
"@vue/eslint-config-typescript": ^5.0.2
744-
concurrently: ^8.2.2
745-
core-js: ^3.6.4
746-
eslint-plugin-vue: ^5.0.0
747-
less: ^3.11.1
748-
less-loader: ^5.0.0
749-
lodash.merge: ^4.6.2
750-
rimraf: ^5.0.7
751-
stylus: ^0.54.5
752-
stylus-loader: ^3.0.2
753-
vite: ^5.1.6
754-
vue: ^3.0.0
755-
vue-demi: "*"
756-
languageName: unknown
757-
linkType: soft
758-
759759
"@types/estree@npm:1.0.5":
760760
version: 1.0.5
761761
resolution: "@types/estree@npm:1.0.5"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"scripts": {
1111
"serve:mock-data": "nodemon --delay 1 --watch mock-data/apis mock-data/server.js",
1212
"serve:mock-submodules": "cd mock-submodules && yarn serve",
13-
"serve:mock": "concurrently --raw \"yarn serve:mock-data\" \"yarn serve:mock-submodules\" ",
13+
"serve": "concurrently --raw \"yarn serve:mock-data\" \"yarn serve:mock-submodules\" \"nuxt dev playground -p 7001\"",
1414
"build": "lerna run build --sort --stream --scope='@vue-async/*'",
1515
"test": "jest --coverage --passWithNoTests",
1616
"prepublishOnly": "yarn install --mode=skip-build && yarn changelog && yarn build && yarn test",
@@ -102,6 +102,7 @@
102102
},
103103
"workspaces": {
104104
"packages": [
105+
"playground",
105106
"packages/*"
106107
]
107108
}

packages/module-loader/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"types"
4848
],
4949
"scripts": {
50-
"serve": "nuxt dev playground -p 7001",
5150
"build": "run -T rimraf -rf lib esm dist && yarn build:version && yarn build:cjs && yarn build:esm && yarn build:umd",
5251
"build:version": "node -p \"'export const version: string = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
5352
"build:cjs": "run -T tsc --project tsconfig.build.json",
@@ -72,8 +71,7 @@
7271
"warning": "^4.0.3"
7372
},
7473
"devDependencies": {
75-
"@types/warning": "^3.0.0",
76-
"nuxt": "^3.0.0"
74+
"@types/warning": "^3.0.0"
7775
},
7876
"peerDependencies": {
7977
"@vue/composition-api": "^1.0.0",

packages/module-loader/playground/pages/remote-component-page.vue

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/module-loader/src/createLoader.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T
1515
*/
1616
export function createLoader<Props extends Record<string, any> = any, Context = any>(
1717
options: {
18+
/**
19+
* global variables for the resolver
20+
*/
1821
globalVariables?: Record<string, any>;
1922
} & XOR<
2023
{

packages/module-loader/playground/nuxt.config.ts renamed to playground/nuxt.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { defineNuxtConfig } from 'nuxt/config';
33

44
export default defineNuxtConfig({
55
ssr: false,
6+
srcDir: 'src/',
67
app: {
78
head: {
89
script: [{ src: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js-loading-overlay.min.js' }],
910
},
1011
},
11-
// plugins: [{ src: 'plugins/module-loader' }],
1212
build: {
1313
transpile: ['@vue-async/*'],
1414
},
1515
alias: {
16-
'@vue-async/module-loader': fileURLToPath(new URL('../src', import.meta.url)),
16+
'@vue-async/module-loader': fileURLToPath(new URL('../packages/module-loader/src', import.meta.url)),
1717
},
1818
});

playground/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@test/playground",
3+
"version": "0.0.1",
4+
"private": true,
5+
"license": "MIT",
6+
"scripts": {
7+
"serve": "nuxt dev -p 7001"
8+
},
9+
"dependencies": {
10+
"nuxt": "^3.0.0"
11+
}
12+
}

playground/src/app.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<div>
3+
<NuxtLayout>
4+
<NuxtPage/>
5+
</NuxtLayout>
6+
</div>
7+
</template>

packages/module-loader/playground/pages/index.vue renamed to playground/src/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</NuxtLink>
1717
<h3>设置错误entry(无法正常加载):</h3>
1818
<NuxtLink style="margin: 0 10px 5px; display: block" :to="{ name: 'wrong-entry-remote-component' }">
19-
setted wrong component entry
19+
setted wrong component entry (show error component after 5s)
2020
</NuxtLink>
2121
<h3>vue-router 异步组件加载过程:</h3>
2222
<NuxtLink style="margin: 0 10px 5px; display: block" :to="{ name: 'lazy-loading-remote-component' }">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<template>
2+
<div>
3+
<h3>这是使用 registerComponents 在页面动态加载远程组件。</h3>
4+
<AsyncComponent />
5+
</div>
6+
</template>
7+
8+
<script lang="ts" setup>
9+
import { defineAsyncComponent } from 'vue-demi';
10+
import { registerComponents } from '@vue-async/module-loader';
11+
12+
const useRemoteComponents = registerComponents({
13+
componentA: {
14+
src: 'http://localhost:7010/componentA/index.umd.js',
15+
styles: 'http://localhost:7010/componentA/style.css',
16+
},
17+
});
18+
19+
const AsyncComponent = defineAsyncComponent(() => {
20+
const remoteComponents = useRemoteComponents();
21+
return remoteComponents.componentA();
22+
});
23+
</script>
24+
25+
<style lang="less" scoped>
26+
h3 {
27+
color: blue;
28+
}
29+
</style>

packages/module-loader/playground/plugins/module-loader.ts renamed to playground/src/plugins/module-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Vue from 'vue';
33
import { defineNuxtPlugin } from 'nuxt/app';
44
import { Router, RouteRecordRaw } from 'vue-router';
55
import { createLoader, registerSubModules, registerComponents } from '@vue-async/module-loader';
6-
import { root, megreRoutes, lazyLoadView } from '../router/utils';
6+
import { lazyLoadView } from '../router/utils';
77

88
// make Vue as global in Vue 3
99
// @ts-ignore

packages/module-loader/playground/router/utils.ts renamed to playground/src/router/utils.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,4 @@
11
import { defineComponent, defineAsyncComponent, h, AsyncComponentOptions, Component } from 'vue-demi';
2-
import { RouteRecordRaw } from 'vue-router';
3-
4-
// 模块中路由配置没有根前缀,用于主程序自定义
5-
export function root(routes: RouteRecordRaw[]) {
6-
return routes.map((route) => {
7-
route.path = '/' + route.path;
8-
return route;
9-
});
10-
}
11-
12-
// 合并路由(将新路由配置合并到老路由配置中)
13-
export const megreRoutes = (oldRoutes: RouteRecordRaw[], newRoutes: RouteRecordRaw[]) => {
14-
newRoutes.forEach((current: RouteRecordRaw) => {
15-
const matchRoute = oldRoutes.find(
16-
(route: RouteRecordRaw) => (current.name && route.name === current.name) || route.path === current.path,
17-
);
18-
if (matchRoute) {
19-
// 如果找到已在在的
20-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
21-
const { children, name, ...restOptions } = current;
22-
Object.assign(matchRoute, restOptions); // 合并路由参数
23-
24-
if (children) {
25-
!matchRoute.children && (matchRoute.children = []);
26-
megreRoutes(matchRoute.children, children);
27-
}
28-
} else {
29-
// 插入到 path:'*'之前
30-
const insertIndex = oldRoutes.findIndex((route: RouteRecordRaw) => route.path === '*');
31-
// 如果没找到
32-
oldRoutes.splice(insertIndex < 0 ? 0 : insertIndex, 0, current);
33-
}
34-
});
35-
};
362

373
const LoadingComponent = defineComponent({
384
render() {
@@ -53,7 +19,7 @@ export function lazyLoadView(
5319
loadingComponent = LoadingComponent,
5420
errorComponent = ErrorComponent,
5521
delay = 200,
56-
timeout = 10000,
22+
timeout = 5000,
5723
suspensible = false,
5824
onError,
5925
}: Omit<AsyncComponentOptions, 'loader'> = {},

0 commit comments

Comments
 (0)