@valaxyjs/devtools 0.0.1
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.
- package/LICENSE +21 -0
- package/build.config.ts +18 -0
- package/dist/client/assets/index-UJyf60Kd.css +387 -0
- package/dist/client/assets/index-vPMPXhW9.js +8058 -0
- package/dist/client/index.html +30 -0
- package/dist/index.cjs +56 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.mjs +48 -0
- package/package.json +38 -0
- package/src/client/App.vue +20 -0
- package/src/client/components.d.ts +13 -0
- package/src/client/index.html +29 -0
- package/src/client/main.ts +16 -0
- package/src/client/pages/index.vue +5 -0
- package/src/client/typed-routes.d.ts +140 -0
- package/src/client/utils/index.ts +1 -0
- package/src/client/vite.config.ts +81 -0
- package/src/dir.ts +10 -0
- package/src/index.ts +2 -0
- package/src/node/README.md +3 -0
- package/src/node/index.ts +57 -0
- package/src/node/types.ts +3 -0
- package/tsconfig.json +21 -0
- package/uno.config.ts +3 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
8
|
+
<title>Valaxy Devtools</title>
|
|
9
|
+
<script type="module" crossorigin src="./assets/index-vPMPXhW9.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="./assets/index-UJyf60Kd.css">
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body data-vite-inspect-mode="DEV">
|
|
14
|
+
<div id="app"></div>
|
|
15
|
+
<script>
|
|
16
|
+
(function () {
|
|
17
|
+
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
18
|
+
const setting = localStorage.getItem('color-schema') || 'auto'
|
|
19
|
+
if (setting === 'dark' || (prefersDark && setting !== 'light'))
|
|
20
|
+
document.documentElement.classList.toggle('dark', true)
|
|
21
|
+
})()
|
|
22
|
+
|
|
23
|
+
; (function () {
|
|
24
|
+
if (!location.pathname.endsWith('/'))
|
|
25
|
+
location.pathname += '/'
|
|
26
|
+
})()
|
|
27
|
+
</script>
|
|
28
|
+
</body>
|
|
29
|
+
|
|
30
|
+
</html>
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const c = require('picocolors');
|
|
4
|
+
const sirv = require('sirv');
|
|
5
|
+
const node_path = require('node:path');
|
|
6
|
+
const node_url = require('node:url');
|
|
7
|
+
|
|
8
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
9
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
10
|
+
|
|
11
|
+
const c__default = /*#__PURE__*/_interopDefaultCompat(c);
|
|
12
|
+
const sirv__default = /*#__PURE__*/_interopDefaultCompat(sirv);
|
|
13
|
+
|
|
14
|
+
const DIR_DIST = typeof __dirname !== "undefined" ? __dirname : node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
15
|
+
const DEVTOOLS_CLIENT_FOLDER = node_path.resolve(DIR_DIST, "../dist/client");
|
|
16
|
+
const DIR_CLIENT = DEVTOOLS_CLIENT_FOLDER;
|
|
17
|
+
|
|
18
|
+
const NAME = "valaxy:devtools";
|
|
19
|
+
function ValaxyDevtools(options) {
|
|
20
|
+
let config;
|
|
21
|
+
function configureServer(server) {
|
|
22
|
+
const _print = server.printUrls;
|
|
23
|
+
const base = (options.base ?? server.config.base) || "/";
|
|
24
|
+
server.middlewares.use(`${base}__valaxy_devtools__`, sirv__default(DIR_CLIENT, {
|
|
25
|
+
single: true,
|
|
26
|
+
dev: true
|
|
27
|
+
}));
|
|
28
|
+
server.printUrls = () => {
|
|
29
|
+
let host = `${config.server.https ? "https" : "http"}://localhost:${config.server.port || "80"}`;
|
|
30
|
+
const url = server.resolvedUrls?.local[0];
|
|
31
|
+
if (url) {
|
|
32
|
+
try {
|
|
33
|
+
const u = new URL(url);
|
|
34
|
+
host = `${u.protocol}//${u.host}`;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.warn("Parse resolved url failed:", error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
_print();
|
|
40
|
+
const colorUrl = (url2) => c__default.green(url2.replace(/:(\d+)\//, (_, port) => `:${c__default.bold(port)}/`));
|
|
41
|
+
console.log(` ${c__default.green("\u279C")} ${c__default.bold("Inspect")}: ${colorUrl(`${host}${base}__inspect/`)}`);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const plugin = {
|
|
45
|
+
name: NAME,
|
|
46
|
+
configResolved(_config) {
|
|
47
|
+
config = _config;
|
|
48
|
+
},
|
|
49
|
+
configureServer(server) {
|
|
50
|
+
configureServer(server);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return plugin;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = ValaxyDevtools;
|
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import c from 'picocolors';
|
|
2
|
+
import sirv from 'sirv';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const DIR_DIST = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const DEVTOOLS_CLIENT_FOLDER = resolve(DIR_DIST, "../dist/client");
|
|
8
|
+
const DIR_CLIENT = DEVTOOLS_CLIENT_FOLDER;
|
|
9
|
+
|
|
10
|
+
const NAME = "valaxy:devtools";
|
|
11
|
+
function ValaxyDevtools(options) {
|
|
12
|
+
let config;
|
|
13
|
+
function configureServer(server) {
|
|
14
|
+
const _print = server.printUrls;
|
|
15
|
+
const base = (options.base ?? server.config.base) || "/";
|
|
16
|
+
server.middlewares.use(`${base}__valaxy_devtools__`, sirv(DIR_CLIENT, {
|
|
17
|
+
single: true,
|
|
18
|
+
dev: true
|
|
19
|
+
}));
|
|
20
|
+
server.printUrls = () => {
|
|
21
|
+
let host = `${config.server.https ? "https" : "http"}://localhost:${config.server.port || "80"}`;
|
|
22
|
+
const url = server.resolvedUrls?.local[0];
|
|
23
|
+
if (url) {
|
|
24
|
+
try {
|
|
25
|
+
const u = new URL(url);
|
|
26
|
+
host = `${u.protocol}//${u.host}`;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.warn("Parse resolved url failed:", error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
_print();
|
|
32
|
+
const colorUrl = (url2) => c.green(url2.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
33
|
+
console.log(` ${c.green("\u279C")} ${c.bold("Inspect")}: ${colorUrl(`${host}${base}__inspect/`)}`);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const plugin = {
|
|
37
|
+
name: NAME,
|
|
38
|
+
configResolved(_config) {
|
|
39
|
+
config = _config;
|
|
40
|
+
},
|
|
41
|
+
configureServer(server) {
|
|
42
|
+
configureServer(server);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return plugin;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { ValaxyDevtools as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@valaxyjs/devtools",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/YunYouJun/valaxy"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./*": "./*"
|
|
15
|
+
},
|
|
16
|
+
"main": "dist/index.mjs",
|
|
17
|
+
"module": "dist/index.mjs",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@rollup/pluginutils": "^5.1.0",
|
|
21
|
+
"picocolors": "^1.0.0",
|
|
22
|
+
"sirv": "^2.0.4"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.3.3",
|
|
26
|
+
"unbuild": "^2.0.0",
|
|
27
|
+
"vite": "^5.0.12"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "rimraf dist && run-s build:*",
|
|
31
|
+
"build:client": "vite build src/client",
|
|
32
|
+
"build:node": "unbuild",
|
|
33
|
+
"dev": "npm run stub && npm run dev:client",
|
|
34
|
+
"dev:client": "vite build src/client --watch",
|
|
35
|
+
"stub": "unbuild --stub",
|
|
36
|
+
"release": "bumpp && npm publish"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted } from 'vue'
|
|
3
|
+
import { isStaticMode } from './utils'
|
|
4
|
+
|
|
5
|
+
onMounted(() => {
|
|
6
|
+
if (isStaticMode)
|
|
7
|
+
document.title = 'Vite Inspect (Production)'
|
|
8
|
+
})
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<template>
|
|
12
|
+
<main grid="~ rows-[min-content_1fr]" size="h-screen w-screen" text="gray-700 dark:gray-200">
|
|
13
|
+
<Suspense>
|
|
14
|
+
<RouterView />
|
|
15
|
+
<template #fallback>
|
|
16
|
+
Loading...
|
|
17
|
+
</template>
|
|
18
|
+
</Suspense>
|
|
19
|
+
</main>
|
|
20
|
+
</template>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* prettier-ignore */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
// Generated by unplugin-vue-components
|
|
5
|
+
// Read more: https://github.com/vuejs/core/pull/3399
|
|
6
|
+
export {}
|
|
7
|
+
|
|
8
|
+
declare module 'vue' {
|
|
9
|
+
export interface GlobalComponents {
|
|
10
|
+
RouterLink: typeof import('vue-router')['RouterLink']
|
|
11
|
+
RouterView: typeof import('vue-router')['RouterView']
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
8
|
+
<title>Valaxy Devtools</title>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body data-vite-inspect-mode="DEV">
|
|
12
|
+
<div id="app"></div>
|
|
13
|
+
<script>
|
|
14
|
+
(function () {
|
|
15
|
+
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
16
|
+
const setting = localStorage.getItem('color-schema') || 'auto'
|
|
17
|
+
if (setting === 'dark' || (prefersDark && setting !== 'light'))
|
|
18
|
+
document.documentElement.classList.toggle('dark', true)
|
|
19
|
+
})()
|
|
20
|
+
|
|
21
|
+
; (function () {
|
|
22
|
+
if (!location.pathname.endsWith('/'))
|
|
23
|
+
location.pathname += '/'
|
|
24
|
+
})()
|
|
25
|
+
</script>
|
|
26
|
+
<script type="module" src="/main.ts"></script>
|
|
27
|
+
</body>
|
|
28
|
+
|
|
29
|
+
</html>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// register vue composition api globally
|
|
2
|
+
import { createApp } from 'vue'
|
|
3
|
+
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
4
|
+
import { routes } from 'vue-router/auto/routes'
|
|
5
|
+
import App from './App.vue'
|
|
6
|
+
|
|
7
|
+
import '@unocss/reset/tailwind.css'
|
|
8
|
+
import 'uno.css'
|
|
9
|
+
|
|
10
|
+
const app = createApp(App)
|
|
11
|
+
const router = createRouter({
|
|
12
|
+
history: createWebHashHistory(),
|
|
13
|
+
routes,
|
|
14
|
+
})
|
|
15
|
+
app.use(router)
|
|
16
|
+
app.mount('#app')
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* prettier-ignore */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
// Generated by unplugin-vue-router. ‼️ DO NOT MODIFY THIS FILE ‼️
|
|
5
|
+
// It's recommended to commit this file.
|
|
6
|
+
// Make sure to add this file to your tsconfig.json file as an "includes" or "files" entry.
|
|
7
|
+
|
|
8
|
+
/// <reference types="unplugin-vue-router/client" />
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
// type safe route locations
|
|
12
|
+
RouteLocationTypedList,
|
|
13
|
+
RouteLocationResolvedTypedList,
|
|
14
|
+
RouteLocationNormalizedTypedList,
|
|
15
|
+
RouteLocationNormalizedLoadedTypedList,
|
|
16
|
+
RouteLocationAsString,
|
|
17
|
+
RouteLocationAsRelativeTypedList,
|
|
18
|
+
RouteLocationAsPathTypedList,
|
|
19
|
+
|
|
20
|
+
// helper types
|
|
21
|
+
// route definitions
|
|
22
|
+
RouteRecordInfo,
|
|
23
|
+
ParamValue,
|
|
24
|
+
ParamValueOneOrMore,
|
|
25
|
+
ParamValueZeroOrMore,
|
|
26
|
+
ParamValueZeroOrOne,
|
|
27
|
+
|
|
28
|
+
// vue-router extensions
|
|
29
|
+
_RouterTyped,
|
|
30
|
+
RouterLinkTyped,
|
|
31
|
+
RouterLinkPropsTyped,
|
|
32
|
+
NavigationGuard,
|
|
33
|
+
UseLinkFnTyped,
|
|
34
|
+
|
|
35
|
+
// data fetching
|
|
36
|
+
_DataLoader,
|
|
37
|
+
_DefineLoaderOptions,
|
|
38
|
+
} from 'unplugin-vue-router/types'
|
|
39
|
+
|
|
40
|
+
declare module 'vue-router/auto/routes' {
|
|
41
|
+
export interface RouteNamedMap {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare module 'vue-router/auto' {
|
|
46
|
+
import type { RouteNamedMap } from 'vue-router/auto/routes'
|
|
47
|
+
|
|
48
|
+
export type RouterTyped = _RouterTyped<RouteNamedMap>
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Type safe version of `RouteLocationNormalized` (the type of `to` and `from` in navigation guards).
|
|
52
|
+
* Allows passing the name of the route to be passed as a generic.
|
|
53
|
+
*/
|
|
54
|
+
export type RouteLocationNormalized<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationNormalizedTypedList<RouteNamedMap>[Name]
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Type safe version of `RouteLocationNormalizedLoaded` (the return type of `useRoute()`).
|
|
58
|
+
* Allows passing the name of the route to be passed as a generic.
|
|
59
|
+
*/
|
|
60
|
+
export type RouteLocationNormalizedLoaded<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationNormalizedLoadedTypedList<RouteNamedMap>[Name]
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Type safe version of `RouteLocationResolved` (the returned route of `router.resolve()`).
|
|
64
|
+
* Allows passing the name of the route to be passed as a generic.
|
|
65
|
+
*/
|
|
66
|
+
export type RouteLocationResolved<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationResolvedTypedList<RouteNamedMap>[Name]
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Type safe version of `RouteLocation` . Allows passing the name of the route to be passed as a generic.
|
|
70
|
+
*/
|
|
71
|
+
export type RouteLocation<Name extends keyof RouteNamedMap = keyof RouteNamedMap> = RouteLocationTypedList<RouteNamedMap>[Name]
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Type safe version of `RouteLocationRaw` . Allows passing the name of the route to be passed as a generic.
|
|
75
|
+
*/
|
|
76
|
+
export type RouteLocationRaw<Name extends keyof RouteNamedMap = keyof RouteNamedMap> =
|
|
77
|
+
| RouteLocationAsString<RouteNamedMap>
|
|
78
|
+
| RouteLocationAsRelativeTypedList<RouteNamedMap>[Name]
|
|
79
|
+
| RouteLocationAsPathTypedList<RouteNamedMap>[Name]
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Generate a type safe params for a route location. Requires the name of the route to be passed as a generic.
|
|
83
|
+
*/
|
|
84
|
+
export type RouteParams<Name extends keyof RouteNamedMap> = RouteNamedMap[Name]['params']
|
|
85
|
+
/**
|
|
86
|
+
* Generate a type safe raw params for a route location. Requires the name of the route to be passed as a generic.
|
|
87
|
+
*/
|
|
88
|
+
export type RouteParamsRaw<Name extends keyof RouteNamedMap> = RouteNamedMap[Name]['paramsRaw']
|
|
89
|
+
|
|
90
|
+
export function useRouter(): RouterTyped
|
|
91
|
+
export function useRoute<Name extends keyof RouteNamedMap = keyof RouteNamedMap>(name?: Name): RouteLocationNormalizedLoadedTypedList<RouteNamedMap>[Name]
|
|
92
|
+
|
|
93
|
+
export const useLink: UseLinkFnTyped<RouteNamedMap>
|
|
94
|
+
|
|
95
|
+
export function onBeforeRouteLeave(guard: NavigationGuard<RouteNamedMap>): void
|
|
96
|
+
export function onBeforeRouteUpdate(guard: NavigationGuard<RouteNamedMap>): void
|
|
97
|
+
|
|
98
|
+
export const RouterLink: RouterLinkTyped<RouteNamedMap>
|
|
99
|
+
export const RouterLinkProps: RouterLinkPropsTyped<RouteNamedMap>
|
|
100
|
+
|
|
101
|
+
// Experimental Data Fetching
|
|
102
|
+
|
|
103
|
+
export function defineLoader<
|
|
104
|
+
P extends Promise<any>,
|
|
105
|
+
Name extends keyof RouteNamedMap = keyof RouteNamedMap,
|
|
106
|
+
isLazy extends boolean = false,
|
|
107
|
+
>(
|
|
108
|
+
name: Name,
|
|
109
|
+
loader: (route: RouteLocationNormalizedLoaded<Name>) => P,
|
|
110
|
+
options?: _DefineLoaderOptions<isLazy>,
|
|
111
|
+
): _DataLoader<Awaited<P>, isLazy>
|
|
112
|
+
export function defineLoader<
|
|
113
|
+
P extends Promise<any>,
|
|
114
|
+
isLazy extends boolean = false,
|
|
115
|
+
>(
|
|
116
|
+
loader: (route: RouteLocationNormalizedLoaded) => P,
|
|
117
|
+
options?: _DefineLoaderOptions<isLazy>,
|
|
118
|
+
): _DataLoader<Awaited<P>, isLazy>
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
_definePage as definePage,
|
|
122
|
+
_HasDataLoaderMeta as HasDataLoaderMeta,
|
|
123
|
+
_setupDataFetchingGuard as setupDataFetchingGuard,
|
|
124
|
+
_stopDataFetchingScope as stopDataFetchingScope,
|
|
125
|
+
} from 'unplugin-vue-router/runtime'
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
declare module 'vue-router' {
|
|
129
|
+
import type { RouteNamedMap } from 'vue-router/auto/routes'
|
|
130
|
+
|
|
131
|
+
export interface TypesConfig {
|
|
132
|
+
beforeRouteUpdate: NavigationGuard<RouteNamedMap>
|
|
133
|
+
beforeRouteLeave: NavigationGuard<RouteNamedMap>
|
|
134
|
+
|
|
135
|
+
$route: RouteLocationNormalizedLoadedTypedList<RouteNamedMap>[keyof RouteNamedMap]
|
|
136
|
+
$router: _RouterTyped<RouteNamedMap>
|
|
137
|
+
|
|
138
|
+
RouterLink: RouterLinkTyped<RouteNamedMap>
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isStaticMode = document.body.getAttribute('data-valaxy-devtools-mode') === 'BUILD'
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { join, resolve } from 'node:path'
|
|
2
|
+
import { defineConfig } from 'vite'
|
|
3
|
+
import Vue from '@vitejs/plugin-vue'
|
|
4
|
+
import Router from 'unplugin-vue-router/vite'
|
|
5
|
+
import Components from 'unplugin-vue-components/vite'
|
|
6
|
+
import Unocss from 'unocss/vite'
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
base: './',
|
|
10
|
+
|
|
11
|
+
resolve: {
|
|
12
|
+
alias: {
|
|
13
|
+
'~/': __dirname,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
plugins: [
|
|
18
|
+
{
|
|
19
|
+
name: 'local-object-transform',
|
|
20
|
+
transform: {
|
|
21
|
+
order: 'post',
|
|
22
|
+
async handler(code) {
|
|
23
|
+
return `${code}\n/* Injected with object hook! */`
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'generate-error',
|
|
29
|
+
load(id) {
|
|
30
|
+
if (id === '/__LOAD_ERROR')
|
|
31
|
+
throw new Error('Load error')
|
|
32
|
+
if (id === '/__TRANSFORM_ERROR')
|
|
33
|
+
return 'transform'
|
|
34
|
+
},
|
|
35
|
+
transform(code, id) {
|
|
36
|
+
if (id === '/__TRANSFORM_ERROR')
|
|
37
|
+
throw new SyntaxError('Transform error')
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
{
|
|
42
|
+
name: 'no-change',
|
|
43
|
+
transform: {
|
|
44
|
+
order: 'post',
|
|
45
|
+
async handler(code) {
|
|
46
|
+
return code
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
Vue({
|
|
52
|
+
script: {
|
|
53
|
+
defineModel: true,
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
|
|
57
|
+
Router({
|
|
58
|
+
routesFolder: ['pages'],
|
|
59
|
+
dts: join(__dirname, 'typed-routes.d.ts'),
|
|
60
|
+
}),
|
|
61
|
+
|
|
62
|
+
Components({
|
|
63
|
+
dirs: ['components'],
|
|
64
|
+
dts: join(__dirname, 'components.d.ts'),
|
|
65
|
+
}),
|
|
66
|
+
Unocss(),
|
|
67
|
+
],
|
|
68
|
+
|
|
69
|
+
optimizeDeps: {
|
|
70
|
+
exclude: [
|
|
71
|
+
'vite-hot-client',
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
build: {
|
|
76
|
+
target: 'esnext',
|
|
77
|
+
outDir: resolve(__dirname, '../../dist/client'),
|
|
78
|
+
minify: false, // 'esbuild',
|
|
79
|
+
emptyOutDir: true,
|
|
80
|
+
},
|
|
81
|
+
})
|
package/src/dir.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { dirname, resolve } from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
|
|
4
|
+
export const DIR_DIST = typeof __dirname !== 'undefined'
|
|
5
|
+
? __dirname
|
|
6
|
+
: dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
|
|
8
|
+
const DEVTOOLS_CLIENT_FOLDER = resolve(DIR_DIST, '../dist/client')
|
|
9
|
+
|
|
10
|
+
export const DIR_CLIENT = DEVTOOLS_CLIENT_FOLDER
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
|
|
2
|
+
import c from 'picocolors'
|
|
3
|
+
import sirv from 'sirv'
|
|
4
|
+
import { DIR_CLIENT } from '../dir'
|
|
5
|
+
import type { ValaxyDevtoolsOptions } from './types'
|
|
6
|
+
|
|
7
|
+
const NAME = 'valaxy:devtools'
|
|
8
|
+
|
|
9
|
+
export default function ValaxyDevtools(options: ValaxyDevtoolsOptions): Plugin {
|
|
10
|
+
let config: ResolvedConfig
|
|
11
|
+
|
|
12
|
+
function configureServer(server: ViteDevServer) {
|
|
13
|
+
const _print = server.printUrls
|
|
14
|
+
const base = (options.base ?? server.config.base) || '/'
|
|
15
|
+
|
|
16
|
+
server.middlewares.use(`${base}__valaxy_devtools__`, sirv(DIR_CLIENT, {
|
|
17
|
+
single: true,
|
|
18
|
+
dev: true,
|
|
19
|
+
}))
|
|
20
|
+
|
|
21
|
+
server.printUrls = () => {
|
|
22
|
+
let host = `${config.server.https ? 'https' : 'http'}://localhost:${config.server.port || '80'}`
|
|
23
|
+
|
|
24
|
+
const url = server.resolvedUrls?.local[0]
|
|
25
|
+
|
|
26
|
+
if (url) {
|
|
27
|
+
try {
|
|
28
|
+
const u = new URL(url)
|
|
29
|
+
host = `${u.protocol}//${u.host}`
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.warn('Parse resolved url failed:', error)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
_print()
|
|
37
|
+
|
|
38
|
+
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.log(` ${c.green('➜')} ${c.bold('Inspect')}: ${colorUrl(`${host}${base}__inspect/`)}`)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const plugin = <Plugin>{
|
|
45
|
+
name: NAME,
|
|
46
|
+
|
|
47
|
+
configResolved(_config) {
|
|
48
|
+
config = _config
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
configureServer(server) {
|
|
52
|
+
configureServer(server)
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return plugin
|
|
57
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"lib": [
|
|
5
|
+
"ESNext",
|
|
6
|
+
"DOM"
|
|
7
|
+
],
|
|
8
|
+
"baseUrl": ".",
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"moduleResolution": "Bundler",
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"types": [
|
|
13
|
+
"vite/client"
|
|
14
|
+
],
|
|
15
|
+
"strict": true,
|
|
16
|
+
"strictNullChecks": true,
|
|
17
|
+
"esModuleInterop": true,
|
|
18
|
+
"skipDefaultLibCheck": true,
|
|
19
|
+
"skipLibCheck": true
|
|
20
|
+
}
|
|
21
|
+
}
|
package/uno.config.ts
ADDED