Ver código fonte

feat(vite): 引入 @uni-helper/vite-plugin-uni-pages

Burt 2 anos atrás
pai
commit
600274d573
7 arquivos alterados com 113 adições e 17 exclusões
  1. 1 0
      package.json
  2. 11 0
      pages.config.ts
  3. 53 0
      pnpm-lock.yaml
  4. 15 15
      src/pages.json
  5. 8 0
      src/pages/index/index.vue
  6. 20 0
      uni-pages.d.ts
  7. 5 2
      vite.config.ts

+ 1 - 0
package.json

@@ -92,6 +92,7 @@
     "@typescript-eslint/parser": "^6.15.0",
     "@uni-helper/uni-app-types": "^0.5.12",
     "@uni-helper/unocss-preset-uni": "^0.2.5",
+    "@uni-helper/vite-plugin-uni-pages": "^0.2.12",
     "@vue/runtime-core": "^3.2.45",
     "@vue/tsconfig": "^0.1.3",
     "autoprefixer": "^10.4.16",

+ 11 - 0
pages.config.ts

@@ -0,0 +1,11 @@
+// pages.config.ts
+import { defineUniPages } from '@uni-helper/vite-plugin-uni-pages'
+
+export default defineUniPages({
+  // 你也可以定义 pages 字段,它具有最高的优先级。
+  pages: [],
+  globalStyle: {
+    navigationBarTextStyle: 'black',
+    navigationBarTitleText: 'vue3-uniapp',
+  },
+})

+ 53 - 0
pnpm-lock.yaml

@@ -97,6 +97,9 @@ devDependencies:
   '@uni-helper/unocss-preset-uni':
     specifier: ^0.2.5
     version: 0.2.5(eslint-import-resolver-typescript@3.6.1)(postcss@8.4.32)(typescript@4.9.5)(vite@4.1.4)
+  '@uni-helper/vite-plugin-uni-pages':
+    specifier: ^0.2.12
+    version: 0.2.12(@types/lodash-es@4.17.12)(lodash-es@4.17.21)(lodash@4.17.21)
   '@vue/runtime-core':
     specifier: ^3.2.45
     version: 3.3.13
@@ -3633,6 +3636,16 @@ packages:
       '@types/node': 20.10.5
     dev: true
 
+  /@types/lodash-es@4.17.12:
+    resolution: {integrity: sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==}
+    dependencies:
+      '@types/lodash': 4.14.202
+    dev: true
+
+  /@types/lodash@4.14.202:
+    resolution: {integrity: sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==}
+    dev: true
+
   /@types/mdast@3.0.15:
     resolution: {integrity: sha512-LnwD+mUEfxWMa1QpDraczIn6k0Ee3SMicuYSSzS6ZYl2gKS09EClnJYGd8Du6rfc5r/GZEk5o1mRb8TaTj03sQ==}
     dependencies:
@@ -3850,6 +3863,10 @@ packages:
       vue3: /vue@3.3.13(typescript@4.9.5)
     dev: true
 
+  /@uni-helper/uni-env@0.0.3:
+    resolution: {integrity: sha512-K6MEnmN7Dg+NnEkfUUhjaKc/rPVY7tcGdsVUKOlC1/z2E6H6zjSSTdJg8z+sVJtZ03Ff1G/MHz2PYDyAS6gjQQ==}
+    dev: true
+
   /@uni-helper/uni-env@0.1.1(eslint-import-resolver-typescript@3.6.1)(typescript@4.9.5):
     resolution: {integrity: sha512-NGQMOyqCF8VAEi3wWbJLKRwqhMldmFvITMs0j/bvVJ2jjUwN+0ofpPF3aHakCGpuY577DRx4coVN2iYmCb75fw==}
     dependencies:
@@ -3887,6 +3904,26 @@ packages:
       - vitest
     dev: true
 
+  /@uni-helper/vite-plugin-uni-pages@0.2.12(@types/lodash-es@4.17.12)(lodash-es@4.17.21)(lodash@4.17.21):
+    resolution: {integrity: sha512-7Y5nX5o8BrUGWQyHYLSHbE5HxzXxkVpis988SDHAPOY+Kl6acpcg2hvfUNM99l1h4l1KwzW/JCr9u4Ib62HkjA==}
+    dependencies:
+      '@uni-helper/uni-env': 0.0.3
+      '@vue/compiler-sfc': 3.3.13
+      chokidar: 3.5.3
+      debug: 4.3.4
+      fast-glob: 3.3.2
+      json5: 2.2.3
+      lodash-unified: 1.0.3(@types/lodash-es@4.17.12)(lodash-es@4.17.21)(lodash@4.17.21)
+      magic-string: 0.30.5
+      unconfig: 0.3.11
+      yaml: 2.3.4
+    transitivePeerDependencies:
+      - '@types/lodash-es'
+      - lodash
+      - lodash-es
+      - supports-color
+    dev: true
+
   /@unocss-applet/preset-applet@0.7.8:
     resolution: {integrity: sha512-KWzYD88eRf7hMa0SZv8X19eT1X1fwkInM47cjNZ36i/2brt77DSnZF3y61F1zxzdf28SRH/wzgkm2e0I7JepCQ==}
     dependencies:
@@ -9870,6 +9907,22 @@ packages:
       p-locate: 5.0.0
     dev: true
 
+  /lodash-es@4.17.21:
+    resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==}
+    dev: true
+
+  /lodash-unified@1.0.3(@types/lodash-es@4.17.12)(lodash-es@4.17.21)(lodash@4.17.21):
+    resolution: {integrity: sha512-WK9qSozxXOD7ZJQlpSqOT+om2ZfcT4yO+03FuzAHD0wF6S0l0090LRPDx3vhTTLZ8cFKpBn+IOcVXK6qOcIlfQ==}
+    peerDependencies:
+      '@types/lodash-es': '*'
+      lodash: '*'
+      lodash-es: '*'
+    dependencies:
+      '@types/lodash-es': 4.17.12
+      lodash: 4.17.21
+      lodash-es: 4.17.21
+    dev: true
+
   /lodash.camelcase@4.3.0:
     resolution: {integrity: sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==}
 

+ 15 - 15
src/pages.json

@@ -1,16 +1,16 @@
-{
-	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
-		{
-			"path": "pages/index/index",
-			"style": {
-				"navigationBarTitleText": "uni-app"
-			}
-		}
-	],
-	"globalStyle": {
-		"navigationBarTextStyle": "black",
-		"navigationBarTitleText": "uni-app",
-		"navigationBarBackgroundColor": "#F8F8F8",
-		"backgroundColor": "#F8F8F8"
-	}
+{
+  "pages": [
+    {
+      "path": "pages/index/index",
+      "type": "home",
+      "style": {
+        "navigationBarTitleText": "我才是标题"
+      }
+    }
+  ],
+  "globalStyle": {
+    "navigationBarTextStyle": "black",
+    "navigationBarTitleText": "vue3-uniapp"
+  },
+  "subPackages": []
 }

+ 8 - 0
src/pages/index/index.vue

@@ -11,6 +11,14 @@
   </view>
 </template>
 
+<route lang="json">
+{
+  "style": {
+    "navigationBarTitleText": "我才是标题"
+  }
+}
+</route>
+
 <script setup lang="ts" name="TestIndex">
 import { ref } from 'vue'
 import { useCountStore } from '@/store/count'

+ 20 - 0
uni-pages.d.ts

@@ -0,0 +1,20 @@
+/* eslint-disable */
+/* prettier-ignore */
+// @ts-nocheck
+// Generated by vite-plugin-uni-pages
+
+interface NavigateToOptions {
+  url: "pages/index/index";
+}
+interface RedirectToOptions extends NavigateToOptions {}
+
+interface SwitchTabOptions {}
+
+type ReLaunchOptions = NavigateToOptions | SwitchTabOptions
+
+declare interface Uni {
+  navigateTo(options: UniNamespace.NavigateToOptions & NavigateToOptions): void
+  redirectTo(options: UniNamespace.RedirectToOptions & RedirectToOptions): void
+  switchTab(options: UniNamespace.SwitchTabOptions & SwitchTabOptions): void
+  reLaunch(options: UniNamespace.ReLaunchOptions & ReLaunchOptions): void
+}

+ 5 - 2
vite.config.ts

@@ -1,6 +1,7 @@
 import path from 'node:path'
 import { defineConfig, loadEnv } from 'vite'
-import uni from '@dcloudio/vite-plugin-uni'
+import Uni from '@dcloudio/vite-plugin-uni'
+import UniPages from '@uni-helper/vite-plugin-uni-pages'
 import dayjs from 'dayjs'
 import svgLoader from 'vite-svg-loader'
 import { visualizer } from 'rollup-plugin-visualizer'
@@ -38,7 +39,9 @@ export default ({ mode }) => {
   console.log(env)
   return defineConfig({
     plugins: [
-      uni(),
+      // https://github.com/uni-helper/vite-plugin-uni-pages
+      UniPages(),
+      Uni(),
       UnoCSS(),
       htmlPlugin(),
       svgLoader(),