From e5839678b37320c24125e581b58375aa3edf0570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sun, 29 Dec 2024 02:44:56 +0800 Subject: [PATCH] chore: optimize auto import --- .github/workflows/build.yml | 4 ---- .github/workflows/goreleaser.yml | 4 ---- .github/workflows/lint.yml | 2 +- web/gen-auto-import.ts | 10 ++++++++++ web/package.json | 9 ++++++--- web/pnpm-lock.yaml | 19 +++++++++++++++++++ 6 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 web/gen-auto-import.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 110ccaffc8..848ad0febe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,13 +26,9 @@ jobs: cache: 'pnpm' cache-dependency-path: web/pnpm-lock.yaml - name: Build frontend - # We need to run the dev server first to generate the auto-imports files run: | cp .env.production .env cp settings/proxy-config.example.ts settings/proxy-config.ts - pnpm dev & - sleep 5 - kill %1 pnpm build - name: Upload frontend uses: actions/upload-artifact@v4 diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 8a0b8dfc38..98c6798710 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -32,13 +32,9 @@ jobs: cache-dependency-path: web/pnpm-lock.yaml - name: Build frontend working-directory: web - # We need to run the dev server first to generate the auto-imports files run: | cp .env.production .env cp settings/proxy-config.example.ts settings/proxy-config.ts - pnpm dev & - sleep 5 - kill %1 pnpm build - name: Set environment variables run: | diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ccd9b10bad..a3c69ea996 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -59,4 +59,4 @@ jobs: cache: 'pnpm' cache-dependency-path: web/pnpm-lock.yaml - name: Run pnpm lint - run: pnpm lint \ No newline at end of file + run: pnpm lint diff --git a/web/gen-auto-import.ts b/web/gen-auto-import.ts new file mode 100644 index 0000000000..253aaa50dd --- /dev/null +++ b/web/gen-auto-import.ts @@ -0,0 +1,10 @@ +import unplugin from './build/plugins/unplugin' + +function genAutoImport() { + const autoImport = unplugin[0] + autoImport.buildStart.call({ + root: process.cwd() + }) +} + +genAutoImport() diff --git a/web/package.json b/web/package.json index 07271822e7..b70811b237 100644 --- a/web/package.json +++ b/web/package.json @@ -12,13 +12,15 @@ }, "scripts": { "dev": "vite", - "build": "run-p type-check build-only copy", + "build": "run-p gen-auto-import type-check build-only copy", "preview": "vite preview", "build-only": "vite build", "type-check": "vue-tsc --build --force", - "lint": "eslint . --fix", + "lint": "run-p gen-auto-import lint-only", + "lint-only": "eslint . --fix", "format": "prettier --write src/", - "copy": "cpx \"dist/**/*\" \"../internal/embed/frontend\" -C" + "copy": "cpx \"dist/**/*\" \"../internal/embed/frontend\" -C", + "gen-auto-import": "tsx gen-auto-import.ts" }, "dependencies": { "@eslint/eslintrc": "^3.2.0", @@ -76,6 +78,7 @@ "prettier": "^3.3.3", "prettier-plugin-organize-imports": "^4.1.0", "sass": "^1.81.0", + "tsx": "^4.19.2", "typescript": "5.7.2", "unocss": "^0.65.0", "unplugin-auto-import": "^0.19.0", diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml index 7b92600ad2..437518b039 100644 --- a/web/pnpm-lock.yaml +++ b/web/pnpm-lock.yaml @@ -168,6 +168,9 @@ importers: sass: specifier: ^1.81.0 version: 1.83.0 + tsx: + specifier: ^4.19.2 + version: 4.19.2 typescript: specifier: 5.7.2 version: 5.7.2 @@ -988,36 +991,42 @@ packages: engines: {node: '>= 10.0.0'} cpu: [arm] os: [linux] + libc: [glibc] '@parcel/watcher-linux-arm-musl@2.5.0': resolution: {integrity: sha512-6uHywSIzz8+vi2lAzFeltnYbdHsDm3iIB57d4g5oaB9vKwjb6N6dRIgZMujw4nm5r6v9/BQH0noq6DzHrqr2pA==} engines: {node: '>= 10.0.0'} cpu: [arm] os: [linux] + libc: [musl] '@parcel/watcher-linux-arm64-glibc@2.5.0': resolution: {integrity: sha512-BfNjXwZKxBy4WibDb/LDCriWSKLz+jJRL3cM/DllnHH5QUyoiUNEp3GmL80ZqxeumoADfCCP19+qiYiC8gUBjA==} engines: {node: '>= 10.0.0'} cpu: [arm64] os: [linux] + libc: [glibc] '@parcel/watcher-linux-arm64-musl@2.5.0': resolution: {integrity: sha512-S1qARKOphxfiBEkwLUbHjCY9BWPdWnW9j7f7Hb2jPplu8UZ3nes7zpPOW9bkLbHRvWM0WDTsjdOTUgW0xLBN1Q==} engines: {node: '>= 10.0.0'} cpu: [arm64] os: [linux] + libc: [musl] '@parcel/watcher-linux-x64-glibc@2.5.0': resolution: {integrity: sha512-d9AOkusyXARkFD66S6zlGXyzx5RvY+chTP9Jp0ypSTC9d4lzyRs9ovGf/80VCxjKddcUvnsGwCHWuF2EoPgWjw==} engines: {node: '>= 10.0.0'} cpu: [x64] os: [linux] + libc: [glibc] '@parcel/watcher-linux-x64-musl@2.5.0': resolution: {integrity: sha512-iqOC+GoTDoFyk/VYSFHwjHhYrk8bljW6zOhPuhi5t9ulqiYq1togGJB5e3PwYVFFfeVgc6pbz3JdQyDoBszVaA==} engines: {node: '>= 10.0.0'} cpu: [x64] os: [linux] + libc: [musl] '@parcel/watcher-win32-arm64@2.5.0': resolution: {integrity: sha512-twtft1d+JRNkM5YbmexfcH/N4znDtjgysFaV9zvZmmJezQsKpkfLYJ+JFV3uygugK6AtIM2oADPkB2AdhBrNig==} @@ -1095,51 +1104,61 @@ packages: resolution: {integrity: sha512-Py5vFd5HWYN9zxBv3WMrLAXY3yYJ6Q/aVERoeUFwiDGiMOWsMs7FokXihSOaT/PMWUty/Pj60XDQndK3eAfE6A==} cpu: [arm] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.29.1': resolution: {integrity: sha512-RiWpGgbayf7LUcuSNIbahr0ys2YnEERD4gYdISA06wa0i8RALrnzflh9Wxii7zQJEB2/Eh74dX4y/sHKLWp5uQ==} cpu: [arm] os: [linux] + libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.29.1': resolution: {integrity: sha512-Z80O+taYxTQITWMjm/YqNoe9d10OX6kDh8X5/rFCMuPqsKsSyDilvfg+vd3iXIqtfmp+cnfL1UrYirkaF8SBZA==} cpu: [arm64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.29.1': resolution: {integrity: sha512-fOHRtF9gahwJk3QVp01a/GqS4hBEZCV1oKglVVq13kcK3NeVlS4BwIFzOHDbmKzt3i0OuHG4zfRP0YoG5OF/rA==} cpu: [arm64] os: [linux] + libc: [musl] '@rollup/rollup-linux-loongarch64-gnu@4.29.1': resolution: {integrity: sha512-5a7q3tnlbcg0OodyxcAdrrCxFi0DgXJSoOuidFUzHZ2GixZXQs6Tc3CHmlvqKAmOs5eRde+JJxeIf9DonkmYkw==} cpu: [loong64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-powerpc64le-gnu@4.29.1': resolution: {integrity: sha512-9b4Mg5Yfz6mRnlSPIdROcfw1BU22FQxmfjlp/CShWwO3LilKQuMISMTtAu/bxmmrE6A902W2cZJuzx8+gJ8e9w==} cpu: [ppc64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.29.1': resolution: {integrity: sha512-G5pn0NChlbRM8OJWpJFMX4/i8OEU538uiSv0P6roZcbpe/WfhEO+AT8SHVKfp8qhDQzaz7Q+1/ixMy7hBRidnQ==} cpu: [riscv64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-s390x-gnu@4.29.1': resolution: {integrity: sha512-WM9lIkNdkhVwiArmLxFXpWndFGuOka4oJOZh8EP3Vb8q5lzdSCBuhjavJsw68Q9AKDGeOOIHYzYm4ZFvmWez5g==} cpu: [s390x] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.29.1': resolution: {integrity: sha512-87xYCwb0cPGZFoGiErT1eDcssByaLX4fc0z2nRM6eMtV9njAfEE6OW3UniAoDhX4Iq5xQVpE6qO9aJbCFumKYQ==} cpu: [x64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-musl@4.29.1': resolution: {integrity: sha512-xufkSNppNOdVRCEC4WKvlR1FBDyqCSCpQeMMgv9ZyXqqtKBfkw1yfGMTUTs9Qsl6WQbJnsGboWCp7pJGkeMhKA==} cpu: [x64] os: [linux] + libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.29.1': resolution: {integrity: sha512-F2OiJ42m77lSkizZQLuC+jiZ2cgueWQL5YC9tjo3AgaEw+KJmVxHGSyQfDUoYR9cci0lAywv2Clmckzulcq6ig==}