From b84074d5a4820aa42e80b09e6ebc7cb34aa54711 Mon Sep 17 00:00:00 2001 From: h_mo <596417202@qq.com> Date: Sun, 28 Jul 2024 23:31:34 +0800 Subject: [PATCH 1/9] =?UTF-8?q?chore(deps):=20=E6=9B=B4=E6=96=B0=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E7=89=88=E6=9C=AC=EF=BC=8C=E6=8F=90=E5=8D=87=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E6=80=A7=E5=92=8C=E7=A8=B3=E5=AE=9A=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 74 ++++++++++++++++----------------- src/pages/login/index.vue | 1 + src/utils/cache/storageCache.ts | 1 + src/utils/is.ts | 1 + 4 files changed, 40 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index 7ae544e..7dca008 100644 --- a/package.json +++ b/package.json @@ -37,59 +37,59 @@ "dependencies": { "@alova/adapter-uniapp": "^1.2.2", "@alova/mock": "^1.5.2", - "@dcloudio/uni-app": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-app-plus": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-components": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-h5": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-i18n": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-alipay": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-baidu": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-lark": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-qq": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-toutiao": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-weixin": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-quickapp-webview": "3.0.0-alpha-4020220240624001", + "@dcloudio/uni-app": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-app-plus": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-components": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-h5": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-i18n": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-mp-alipay": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-mp-baidu": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-mp-lark": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-mp-qq": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-mp-toutiao": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-mp-weixin": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-quickapp-webview": "3.0.0-alpha-4020520240726003", "@multiavatar/multiavatar": "^1.0.7", - "alova": "^2.21.3", + "alova": "^2.21.4", "crypto-js": "^4.2.0", "lodash-es": "^4.17.21", - "pinia": "^2.1.7", - "vue": "^3.4.30" + "pinia": "^2.2.0", + "vue": "^3.4.34" }, "devDependencies": { - "@antfu/eslint-config": "^2.21.1", - "@dcloudio/types": "^3.4.8", - "@dcloudio/uni-automator": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-cli-shared": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-stacktracey": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-vue-devtools": "3.0.0-alpha-4020220240624001", - "@dcloudio/vite-plugin-uni": "3.0.0-alpha-4020220240624001", - "@iconify/json": "^2.2.206", + "@antfu/eslint-config": "^2.24.0", + "@dcloudio/types": "^3.4.12", + "@dcloudio/uni-automator": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-cli-shared": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-stacktracey": "3.0.0-alpha-4020520240726003", + "@dcloudio/uni-vue-devtools": "3.0.0-alpha-4020520240726003", + "@dcloudio/vite-plugin-uni": "3.0.0-alpha-4020520240726003", + "@iconify/json": "^2.2.231", "@types/crypto-js": "^4.2.2", "@types/lodash-es": "^4.17.12", - "@types/node": "^20.14.8", - "@unocss/eslint-plugin": "^0.61.0", - "@vitejs/plugin-vue": "^5.0.5", - "@vue/runtime-core": "^3.4.30", - "eslint": "^9.5.0", + "@types/node": "^20.14.13", + "@unocss/eslint-plugin": "^0.61.6", + "@vitejs/plugin-vue": "^5.1.1", + "@vue/runtime-core": "^3.4.34", + "eslint": "^9.8.0", "eslint-plugin-format": "^0.1.2", - "globals": "^15.6.0", + "globals": "^15.8.0", "lint-staged": "^15.2.7", "picocolors": "^1.0.1", "rollup-plugin-visualizer": "^5.12.0", - "sass": "^1.77.6", + "sass": "^1.77.8", "simple-git-hooks": "^2.11.1", - "tsx": "^4.15.7", - "typescript": "^5.5.2", + "tsx": "^4.16.2", + "typescript": "^5.5.4", "uni-mini-router": "^0.1.6", "uni-read-pages-vite": "^0.0.6", - "unocss": "^0.61.0", + "unocss": "^0.61.6", "unocss-preset-weapp": "^0.60.1", - "unplugin-auto-import": "^0.17.6", + "unplugin-auto-import": "^0.17.8", "unplugin-transform-class": "^0.5.3", - "vite": "^5.3.1", - "vite-plugin-restart": "^0.4.0" + "vite": "^5.3.5", + "vite-plugin-restart": "^0.4.1" }, "simple-git-hooks": { "pre-commit": "npx lint-staged", diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index 54e48f8..72df7ae 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -25,6 +25,7 @@ function submit(e: any) { const params = omit(unref(pageQuery), ['redirect', 'tabBar']); if (unref(pageQuery)) { // 这里replace方法无法跳转tabbar页面故改为replaceAll + // eslint-disable-next-line ts/no-unused-expressions unref(pageQuery)?.tabBar === 'true' ? router.replaceAll({ name: unref(pageQuery)?.redirect, params }) : router.replace({ name: unref(pageQuery)?.redirect, params }); diff --git a/src/utils/cache/storageCache.ts b/src/utils/cache/storageCache.ts index 4515208..395abf4 100644 --- a/src/utils/cache/storageCache.ts +++ b/src/utils/cache/storageCache.ts @@ -85,6 +85,7 @@ export function createStorage({ return def; } return value; + // eslint-disable-next-line unused-imports/no-unused-vars } catch (e) { return def; } diff --git a/src/utils/is.ts b/src/utils/is.ts index 824494c..f88c849 100644 --- a/src/utils/is.ts +++ b/src/utils/is.ts @@ -60,6 +60,7 @@ export function isString(val: unknown): val is string { return is(val, 'String'); } +// eslint-disable-next-line ts/no-unsafe-function-type export function isFunction(val: unknown): val is Function { return typeof val === 'function'; } From 626781e26a96d02b40316d356361e2c94d400da7 Mon Sep 17 00:00:00 2001 From: h_mo <596417202@qq.com> Date: Mon, 19 Aug 2024 14:44:34 +0800 Subject: [PATCH 2/9] =?UTF-8?q?chore(deps):=20=E4=BE=9D=E8=B5=96=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=92=8Cregistry=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新多项依赖以保持最新,包括`@dcloudio/uni-app`和其他相关库至最新alpha版本,以及`alova`和`vue`等。 - 将npm registry更改为https://registry.npmmirror.com,以改善国内访问速度和可靠性。 - `package.json`中具体版本号的变动反映在`dependencies`和`devDependencies`部分,确保使用最新稳定版本。- .npmrc文件中registry的更改将影响所有npm安装操作,提供一个更快的国内镜像源。 --- .npmrc | 4 +-- package.json | 78 ++++++++++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/.npmrc b/.npmrc index 152f324..54d704c 100644 --- a/.npmrc +++ b/.npmrc @@ -2,5 +2,5 @@ # 提示:如果你不希望pnpm在对等依赖问题上失败,在项目根目录下的.npmrc文件中添加"strict-peer-dependencies=false"。 # auto-install-peers=true strict-peer-dependencies=false -# registry=https://registry.npmmirror.com -registry=https://registry.npmjs.org +registry=https://registry.npmmirror.com +# registry=https://registry.npmjs.org diff --git a/package.json b/package.json index 7ae544e..e40ade6 100644 --- a/package.json +++ b/package.json @@ -37,59 +37,59 @@ "dependencies": { "@alova/adapter-uniapp": "^1.2.2", "@alova/mock": "^1.5.2", - "@dcloudio/uni-app": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-app-plus": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-components": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-h5": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-i18n": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-alipay": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-baidu": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-lark": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-qq": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-toutiao": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-mp-weixin": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-quickapp-webview": "3.0.0-alpha-4020220240624001", + "@dcloudio/uni-app": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-app-plus": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-components": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-h5": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-i18n": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-mp-alipay": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-mp-baidu": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-mp-lark": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-mp-qq": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-mp-toutiao": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-mp-weixin": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-quickapp-webview": "3.0.0-alpha-4020520240808001", "@multiavatar/multiavatar": "^1.0.7", - "alova": "^2.21.3", + "alova": "^2.21.4", "crypto-js": "^4.2.0", "lodash-es": "^4.17.21", - "pinia": "^2.1.7", - "vue": "^3.4.30" + "pinia": "^2.2.2", + "vue": "^3.4.38" }, "devDependencies": { - "@antfu/eslint-config": "^2.21.1", - "@dcloudio/types": "^3.4.8", - "@dcloudio/uni-automator": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-cli-shared": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-stacktracey": "3.0.0-alpha-4020220240624001", - "@dcloudio/uni-vue-devtools": "3.0.0-alpha-4020220240624001", - "@dcloudio/vite-plugin-uni": "3.0.0-alpha-4020220240624001", - "@iconify/json": "^2.2.206", + "@antfu/eslint-config": "^2.26.0", + "@dcloudio/types": "^3.4.12", + "@dcloudio/uni-automator": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-cli-shared": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-stacktracey": "3.0.0-alpha-4020520240808001", + "@dcloudio/uni-vue-devtools": "3.0.0-alpha-4020520240808001", + "@dcloudio/vite-plugin-uni": "3.0.0-alpha-4020520240808001", + "@iconify/json": "^2.2.238", "@types/crypto-js": "^4.2.2", "@types/lodash-es": "^4.17.12", - "@types/node": "^20.14.8", - "@unocss/eslint-plugin": "^0.61.0", - "@vitejs/plugin-vue": "^5.0.5", - "@vue/runtime-core": "^3.4.30", - "eslint": "^9.5.0", + "@types/node": "^20.16.1", + "@unocss/eslint-plugin": "^0.61.9", + "@vitejs/plugin-vue": "^5.1.2", + "@vue/runtime-core": "^3.4.38", + "eslint": "^9.9.0", "eslint-plugin-format": "^0.1.2", - "globals": "^15.6.0", - "lint-staged": "^15.2.7", + "globals": "^15.9.0", + "lint-staged": "^15.2.9", "picocolors": "^1.0.1", "rollup-plugin-visualizer": "^5.12.0", - "sass": "^1.77.6", + "sass": "^1.77.8", "simple-git-hooks": "^2.11.1", - "tsx": "^4.15.7", - "typescript": "^5.5.2", + "tsx": "^4.17.0", + "typescript": "^5.5.4", "uni-mini-router": "^0.1.6", "uni-read-pages-vite": "^0.0.6", - "unocss": "^0.61.0", - "unocss-preset-weapp": "^0.60.1", - "unplugin-auto-import": "^0.17.6", + "unocss": "^0.62.2", + "unocss-preset-weapp": "^0.62.0", + "unplugin-auto-import": "^0.18.2", "unplugin-transform-class": "^0.5.3", - "vite": "^5.3.1", - "vite-plugin-restart": "^0.4.0" + "vite": "^5.4.1", + "vite-plugin-restart": "^0.4.1" }, "simple-git-hooks": { "pre-commit": "npx lint-staged", From 09e4093acaeb8116427bfee595d5b418fc55b13a Mon Sep 17 00:00:00 2001 From: h_mo <596417202@qq.com> Date: Mon, 19 Aug 2024 17:52:52 +0800 Subject: [PATCH 3/9] =?UTF-8?q?refactor:=20tailwindcss=20=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=20unocss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .npmrc | 4 +- build/platform.ts | 15 ++++ build/vitePlugins.ts | 57 +++++++++++++++ eslint.config.js | 1 - package.json | 13 ++-- postcss.config.ts | 12 ++++ src/App.vue | 3 + src/main.ts | 1 - src/pages/demo/index.vue | 2 +- src/pages/index/index.vue | 2 +- src/pages/notFound/404.vue | 2 +- src/types/unplugin-transform-class-vite.d.ts | 4 -- tailwind.config.js | 11 +++ tsconfig.json | 2 +- unocss.config.js | 73 -------------------- vite.config.ts | 55 +++------------ 16 files changed, 119 insertions(+), 138 deletions(-) create mode 100644 build/platform.ts create mode 100644 build/vitePlugins.ts create mode 100644 postcss.config.ts delete mode 100644 src/types/unplugin-transform-class-vite.d.ts create mode 100644 tailwind.config.js delete mode 100644 unocss.config.js diff --git a/.npmrc b/.npmrc index 152f324..54d704c 100644 --- a/.npmrc +++ b/.npmrc @@ -2,5 +2,5 @@ # 提示:如果你不希望pnpm在对等依赖问题上失败,在项目根目录下的.npmrc文件中添加"strict-peer-dependencies=false"。 # auto-install-peers=true strict-peer-dependencies=false -# registry=https://registry.npmmirror.com -registry=https://registry.npmjs.org +registry=https://registry.npmmirror.com +# registry=https://registry.npmjs.org diff --git a/build/platform.ts b/build/platform.ts new file mode 100644 index 0000000..c7feb67 --- /dev/null +++ b/build/platform.ts @@ -0,0 +1,15 @@ +import process from 'node:process'; + +const currentPlatform = process.env.UNI_PLATFORM; +const isH5 = currentPlatform === 'h5'; +const isApp = currentPlatform === 'app'; +const WeappTailwindcssDisabled = isH5 || isApp; +const isMp = !isH5 && !isApp; + +export { + isH5, + isApp, + WeappTailwindcssDisabled, + isMp, + currentPlatform, +}; diff --git a/build/vitePlugins.ts b/build/vitePlugins.ts new file mode 100644 index 0000000..f614f3e --- /dev/null +++ b/build/vitePlugins.ts @@ -0,0 +1,57 @@ +import type { PluginOption } from 'vite'; +import uni from '@dcloudio/vite-plugin-uni'; +import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'; +import autoImport from 'unplugin-auto-import/vite'; +import viteRestart from 'vite-plugin-restart'; +import { visualizer } from 'rollup-plugin-visualizer'; +import { WeappTailwindcssDisabled, isH5 } from './platform'; + +interface VitePluginConfig { + isProd: boolean +} + +export function createVitePlugins({ isProd }: VitePluginConfig): PluginOption[] { + return [ + // @ts-expect-error TODO uni() 会报错:uni is not a function,暂时使用此方式解决 + uni?.default(), + uvtw({ + rem2rpx: true, + disabled: WeappTailwindcssDisabled, + // 使用新的 ast-grep 来处理 js 资源,速度是 babel 的2倍左右 + // 需要先安装 `@ast-grep/napi` + // jsAstTool: 'ast-grep' + }), + autoImport({ + include: [ + /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx + /\.vue$/, + /\.vue\?vue/, // .vue + ], + imports: [ + 'vue', + 'uni-app', + 'pinia', + { + 'uni-mini-router': ['useRouter', 'useRoute'], + }, + { + alova: ['useRequest'], + }, + ], + dts: 'typings/auto-imports.d.ts', + eslintrc: { + enabled: true, + }, + }), + viteRestart({ + restart: ['vite.config.ts', 'src/pages.json'], + }), + isH5 && isProd + && visualizer({ + filename: './node_modules/.cache/visualizer/stats.html', + open: true, + gzipSize: true, + brotliSize: true, + }), + ]; +} diff --git a/eslint.config.js b/eslint.config.js index 98b72d7..fbdc545 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -12,7 +12,6 @@ export default antfu( formatters: true, vue: true, jsx: true, - unocss: true, env: { node: true, }, diff --git a/package.json b/package.json index e40ade6..3650576 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei", "build:quickapp-webview-union": "uni build -p quickapp-webview-union", "lint:fix": "eslint . --fix", - "git:hooks": "npx simple-git-hooks" + "git:hooks": "npx simple-git-hooks", + "postinstall": "weapp-tw patch" }, "dependencies": { "@alova/adapter-uniapp": "^1.2.2", @@ -69,27 +70,27 @@ "@types/crypto-js": "^4.2.2", "@types/lodash-es": "^4.17.12", "@types/node": "^20.16.1", - "@unocss/eslint-plugin": "^0.61.9", "@vitejs/plugin-vue": "^5.1.2", "@vue/runtime-core": "^3.4.38", + "autoprefixer": "^10.4.20", "eslint": "^9.9.0", "eslint-plugin-format": "^0.1.2", "globals": "^15.9.0", "lint-staged": "^15.2.9", "picocolors": "^1.0.1", + "postcss": "^8.4.41", "rollup-plugin-visualizer": "^5.12.0", "sass": "^1.77.8", "simple-git-hooks": "^2.11.1", + "tailwindcss": "^3.4.10", "tsx": "^4.17.0", "typescript": "^5.5.4", "uni-mini-router": "^0.1.6", "uni-read-pages-vite": "^0.0.6", - "unocss": "^0.62.2", - "unocss-preset-weapp": "^0.62.0", "unplugin-auto-import": "^0.18.2", - "unplugin-transform-class": "^0.5.3", "vite": "^5.4.1", - "vite-plugin-restart": "^0.4.1" + "vite-plugin-restart": "^0.4.1", + "weapp-tailwindcss": "^3.5.0" }, "simple-git-hooks": { "pre-commit": "npx lint-staged", diff --git a/postcss.config.ts b/postcss.config.ts new file mode 100644 index 0000000..a16dcd9 --- /dev/null +++ b/postcss.config.ts @@ -0,0 +1,12 @@ +import tailwindcss from 'tailwindcss'; +import autoprefixer from 'autoprefixer'; +import type { AcceptedPlugin } from 'postcss'; +import cssMacro from 'weapp-tailwindcss/css-macro/postcss'; + +const plugins: AcceptedPlugin[] = [tailwindcss(), autoprefixer()]; + +// 可以使用 postcss-pxtransform 来进行 px 转 rpx 的功能 + +plugins.push(cssMacro); + +export default plugins; diff --git a/src/App.vue b/src/App.vue index 735c9d7..d464290 100644 --- a/src/App.vue +++ b/src/App.vue @@ -16,4 +16,7 @@ onHide(() => { diff --git a/src/main.ts b/src/main.ts index c4c1a43..c723877 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,5 @@ import { createSSRApp } from 'vue'; import App from './App.vue'; -import 'virtual:uno.css'; import { setupRouter } from './router'; import { setupStore } from './stores'; diff --git a/src/pages/demo/index.vue b/src/pages/demo/index.vue index 304f519..e4a9905 100644 --- a/src/pages/demo/index.vue +++ b/src/pages/demo/index.vue @@ -5,7 +5,7 @@ const demo = ref('Demo');