@minar-kotonoha/vite-plugin-miko 0.2.1 → 0.2.3

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/index.ts CHANGED
@@ -119,10 +119,12 @@ const DEFAULTS = {
119
119
  // ===================================================================
120
120
 
121
121
  function detectTemplate(): string {
122
+ // 优先项目本地 template/(用户可覆盖)
122
123
  const local = resolve(cwd, 'template')
123
124
  if (existsSync(local)) return local
124
- const pkgRelative = fileURLToPath(new URL('../../template', import.meta.url))
125
- if (existsSync(pkgRelative)) return pkgRelative
125
+ // 回退到插件内置 template/
126
+ const bundled = fileURLToPath(new URL('./template', import.meta.url))
127
+ if (existsSync(bundled)) return bundled
126
128
  return local
127
129
  }
128
130
 
package/package.json CHANGED
@@ -1,19 +1,24 @@
1
1
  {
2
2
  "name": "@minar-kotonoha/vite-plugin-miko",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.ts",
7
7
  "./package.json": "./package.json"
8
8
  },
9
9
  "peerDependencies": {
10
- "vite": "catalog:"
10
+ "vite": "^8.1.0"
11
11
  },
12
+ "files": [
13
+ "index.ts",
14
+ "types.ts",
15
+ "template/"
16
+ ],
12
17
  "dependencies": {
13
- "@minar-kotonoha/linter": "workspace:^",
14
- "@minar-kotonoha/vite-plugin-bootstrap": "workspace:^",
15
- "@minar-kotonoha/vite-plugin-external": "workspace:^",
16
- "@minar-kotonoha/vite-plugin-index-html": "workspace:^",
18
+ "@minar-kotonoha/linter": "^0.1.0",
19
+ "@minar-kotonoha/vite-plugin-bootstrap": "^0.1.1",
20
+ "@minar-kotonoha/vite-plugin-external": "^0.1.0",
21
+ "@minar-kotonoha/vite-plugin-index-html": "^0.1.0",
17
22
  "@vant/auto-import-resolver": "^1.3.0",
18
23
  "@vitejs/plugin-legacy": "^8.2.2",
19
24
  "@vitejs/plugin-vue": "^6.0.8",
@@ -0,0 +1,76 @@
1
+ <script setup lang="ts">
2
+ import { useRoute } from 'vue-router';
3
+ import { useHead } from '@minar-kotonoha/framework/modules/@unhead/vue.ts';
4
+ import skeletonStyles from './styles/skeleton.less?inline';
5
+ import hiddenVCloakStyles from './styles/hiddenVCloak.less?inline';
6
+ import Fallback from './components/Fallback.vue';
7
+
8
+ const onResolve = () => {
9
+ if (!import.meta.env.SSR) {
10
+ document.getElementById('app')!.removeAttribute('v-cloak');
11
+ }
12
+ };
13
+ const useSkeleton = useRoute().meta.useSkeleton ?? true;
14
+ const isDev = import.meta.env.DEV;
15
+
16
+ // 此处在预渲染时完成,故加个判断,客户端代码会剔除这块,减小包体积
17
+ if (import.meta.env.SSR) {
18
+ // 生产环境 Framework CDN 地址,可通过 VITE_FRAMEWORK_CDN 自定义
19
+ // 默认使用 unpkg CDN,配合 @minar-kotonoha/framework 发布版本
20
+ const frameworkCDN = import.meta.env.VITE_FRAMEWORK_CDN
21
+ || `https://unpkg.com/@minar-kotonoha/framework@${import.meta.env.VITE_LIB_VERSION}/dist/framework_v${import.meta.env.VITE_LIB_VERSION}.umd.js`;
22
+ const framework = frameworkCDN;
23
+ useHead({
24
+ style: useSkeleton ? [skeletonStyles] : [hiddenVCloakStyles],
25
+ script: [
26
+ {
27
+ src: framework,
28
+ tagPosition: 'bodyClose',
29
+ },
30
+ ],
31
+ link: [
32
+ {
33
+ rel: 'preload',
34
+ href: framework,
35
+ as: 'script',
36
+ },
37
+ ],
38
+ });
39
+ }
40
+ </script>
41
+
42
+ <template>
43
+ <RouterView v-slot="{ Component, route }">
44
+ <Suspense @resolve="onResolve">
45
+ <ClientOnly v-if="(console.log(`路由${route.fullPath}使用预渲染:${!route.meta.clientOnly}`), route.meta.clientOnly)">
46
+ <component :is="Component" />
47
+ </ClientOnly>
48
+ <component :is="Component" v-else />
49
+ <template v-if="isDev" #fallback>
50
+ <!-- 只有在开发环境才会走fallback -->
51
+ <Fallback />
52
+ </template>
53
+ </Suspense>
54
+ </RouterView>
55
+ </template>
56
+ <style lang="less">
57
+ body {
58
+ margin: 0;
59
+ }
60
+
61
+ [v-cloak] > .loading {
62
+ position: fixed;
63
+ top: 50%;
64
+ left: 50%;
65
+ visibility: visible;
66
+ transform: translate(-50%, -50%);
67
+ transition-duration: 0.5s;
68
+ transition-property: opacity;
69
+ opacity: 0;
70
+ }
71
+
72
+ /* 同上:https://unocss.dev/integrations/runtime#preventing-fouc */
73
+ [un-cloak] {
74
+ display: none;
75
+ }
76
+ </style>
@@ -0,0 +1,12 @@
1
+ <template>
2
+ <div class="center">加载中</div>
3
+ </template>
4
+ <script setup lang="ts"></script>
5
+ <style scoped>
6
+ .center {
7
+ position: fixed;
8
+ top: 50%;
9
+ left: 50%;
10
+ transform: translate(-50%, -50%);
11
+ }
12
+ </style>
@@ -0,0 +1,15 @@
1
+ <!doctype html>
2
+ <html lang="zh-cmn-Hans">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" href="/favicon.ico" />
6
+ <meta
7
+ content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=0,viewport-fit=cover"
8
+ name="viewport"
9
+ />
10
+ </head>
11
+ <body>
12
+ <div id="app" v-cloak="true" data-allow-mismatch=""></div>
13
+ <script type="module">import 'virtual:index';</script>
14
+ </body>
15
+ </html>
@@ -0,0 +1,11 @@
1
+ <script setup lang="ts">
2
+ import { provide } from 'vue'
3
+ import { useRouter, routerKey } from 'vue-router'
4
+
5
+ // 显式 provide router 确保嵌套 RouterView 内子组件注入可靠
6
+ provide(routerKey, useRouter())
7
+ </script>
8
+
9
+ <template>
10
+ <RouterView />
11
+ </template>
@@ -0,0 +1,38 @@
1
+ import App from './App.vue';
2
+
3
+ // 多语言会让包体积增加100K,默认关闭
4
+ // import { createI18n } from 'vue-i18n';
5
+ // import messages from '@intlify/unplugin-vue-i18n/messages';
6
+
7
+ import { ViteSSG } from 'vite-ssg';
8
+
9
+ import { setupLayouts } from 'virtual:generated-layouts';
10
+ import { routes, handleHotUpdate } from 'vue-router/auto-routes';
11
+
12
+ import { bootstrap } from 'virtual:bootstrap';
13
+
14
+ import 'virtual:uno.css';
15
+
16
+ export const createApp = ViteSSG(
17
+ // the root component
18
+ App,
19
+ // vue-router options
20
+ { routes: setupLayouts(routes) },
21
+ // function to have custom setups
22
+ async ({ app, router }) => {
23
+ // const i18n = createI18n({
24
+ // locale: 'zh-CN',
25
+ // messages,
26
+ // });
27
+ // app.use(i18n);
28
+
29
+ if (import.meta.hot) {
30
+ handleHotUpdate(router);
31
+ }
32
+
33
+ await bootstrap(app, router);
34
+ },
35
+ {
36
+ hydration: import.meta.env.PROD,
37
+ },
38
+ );
Binary file
@@ -0,0 +1,3 @@
1
+ [v-cloak] > * {
2
+ visibility: hidden;
3
+ }
@@ -0,0 +1,49 @@
1
+ [v-cloak],
2
+ .skeleton {
3
+ pointer-events: none !important;
4
+
5
+ // 光柱特效
6
+ &::before {
7
+ content: '';
8
+ position: fixed;
9
+ width: 25vw;
10
+ height: 100%;
11
+ top: 0;
12
+ left: 0;
13
+ transform: translateX(-25vw);
14
+ overflow: hidden;
15
+ background-image: linear-gradient(
16
+ to left,
17
+ rgba(255, 255, 255, 0) 0,
18
+ rgba(255, 255, 255, 1) 50%,
19
+ rgba(255, 255, 255, 0) 100%
20
+ );
21
+ animation: shimmer 1.25s linear infinite;
22
+ z-index: 1000;
23
+ }
24
+
25
+ @keyframes shimmer {
26
+ 0% {
27
+ transform: translateX(-25vw);
28
+ }
29
+ 100% {
30
+ transform: translateX(100vw);
31
+ }
32
+ }
33
+
34
+ * {
35
+ white-space: nowrap !important;
36
+ border-color: transparent !important;
37
+ color: transparent !important;
38
+ &::first-line {
39
+ background-color: #e8e6e850;
40
+ }
41
+ &::placeholder {
42
+ color: transparent !important;
43
+ }
44
+ }
45
+ i,
46
+ img {
47
+ visibility: hidden !important;
48
+ }
49
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "@minar-kotonoha/linter/tsconfig.json",
3
+ "include": ["**/*", "**/*.vue", "../packages/plugins/bootstrap/index.d.ts"],
4
+ "exclude": ["**/__tests__/*", "e2e/**/*", "**/node_modules/*", "**/dist/*"],
5
+ "compilerOptions": {
6
+ "baseUrl": ".",
7
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
8
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
9
+ "types": [
10
+ "vite/client",
11
+ "vite-plugin-vue-layouts-next/client",
12
+ "vue-macros/macros-global",
13
+ "@intlify/unplugin-vue-i18n/messages"
14
+ ]
15
+ },
16
+ "vueCompilerOptions": {
17
+ "plugins": ["vue-macros/volar"]
18
+ }
19
+ }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "esnext",
4
- "moduleResolution": "bundler",
5
- "target": "esnext",
6
- "lib": ["esnext", "dom"],
7
- "strict": true,
8
- "types": ["node", "vite/client"]
9
- },
10
- "include": ["index.ts", "types.ts"]
11
- }