From 00d9643e391cfdbfc6d157fa18a5a6742681aaf2 Mon Sep 17 00:00:00 2001 From: buqiyuan <1743369777@qq.com> Date: Sun, 24 Mar 2024 01:19:55 +0800 Subject: [PATCH] chore: upgrade deps & add postinstall script --- package.json | 23 ++++-- pnpm-lock.yaml | 166 ++++++++++++++++++++++++++++++++--------- scripts/postinstall.js | 26 +++++++ vite.config.ts | 7 ++ 4 files changed, 181 insertions(+), 41 deletions(-) create mode 100644 scripts/postinstall.js diff --git a/package.json b/package.json index 6c743ab1d..23daaf637 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "scripts": { "preinstall": "npx only-allow pnpm", - "postinstall": "pnpm nx:build", + "postinstall": "node ./scripts/postinstall.js || pnpm build:pkg", "bootstrap": "pnpm install", "serve": "npm run dev", "dev": "vite dev", @@ -100,7 +100,8 @@ "husky": "~9.0.11", "less": "~4.2.0", "lint-staged": "~15.2.2", - "msw": "^2.2.9", + "msw": "^2.2.10", + "nx": "18.1.2", "postcss": "~8.4.38", "postcss-html": "~1.6.0", "postcss-less": "~6.0.0", @@ -117,14 +118,13 @@ "typescript": "~5.4.3", "unocss": "^0.58.6", "unplugin-vue-components": "~0.26.0", - "vite": "~5.2.2", + "vite": "~5.2.4", "vite-plugin-checker": "~0.6.4", "vite-plugin-inspect": "^0.8.3", "vite-plugin-mkcert": "^1.17.5", "vite-plugin-svg-icons": "~2.0.1", "vue-eslint-parser": "~9.4.2", - "vue-tsc": "~1.8.27", - "nx": "18.1.2" + "vue-tsc": "~1.8.27" }, "__npminstall_done": false, "repository": { @@ -143,7 +143,18 @@ ], "license": "MIT", "target": "web", + "dependenciesMeta": { + "@admin-pkg/vite-plugin-msw": { + "injected": true + }, + "@admin-pkg/vite-plugin-tinymce-resource": { + "injected": true + } + }, "pnpm": { "overrides": {} - } + }, + "workspaces": [ + "packages/*" + ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 13d1d671c..e21857b0d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,10 +92,10 @@ importers: version: link:packages/components '@admin-pkg/vite-plugin-msw': specifier: workspace:* - version: link:packages/vite-plugin-msw + version: file:packages/vite-plugin-msw(msw@2.2.10) '@admin-pkg/vite-plugin-tinymce-resource': specifier: workspace:* - version: link:packages/vite-plugin-tinymce-resource + version: file:packages/vite-plugin-tinymce-resource(vite@5.2.4) '@commitlint/cli': specifier: ~19.2.1 version: 19.2.1(@types/node@20.11.30)(typescript@5.4.3) @@ -137,10 +137,10 @@ importers: version: 1.11.1 '@vitejs/plugin-vue': specifier: ~5.0.4 - version: 5.0.4(vite@5.2.2)(vue@3.4.21) + version: 5.0.4(vite@5.2.4)(vue@3.4.21) '@vitejs/plugin-vue-jsx': specifier: ~3.1.0 - version: 3.1.0(vite@5.2.2)(vue@3.4.21) + version: 3.1.0(vite@5.2.4)(vue@3.4.21) '@vue/tsconfig': specifier: ^0.5.1 version: 0.5.1 @@ -187,8 +187,8 @@ importers: specifier: ~15.2.2 version: 15.2.2 msw: - specifier: ^2.2.9 - version: 2.2.9(typescript@5.4.3) + specifier: ^2.2.10 + version: 2.2.10(typescript@5.4.3) nx: specifier: 18.1.2 version: 18.1.2 @@ -236,31 +236,36 @@ importers: version: 5.4.3 unocss: specifier: ^0.58.6 - version: 0.58.6(postcss@8.4.38)(vite@5.2.2) + version: 0.58.6(postcss@8.4.38)(vite@5.2.4) unplugin-vue-components: specifier: ~0.26.0 version: 0.26.0(vue@3.4.21) vite: - specifier: ~5.2.2 - version: 5.2.2(@types/node@20.11.30)(less@4.2.0) + specifier: ~5.2.4 + version: 5.2.4(@types/node@20.11.30)(less@4.2.0) vite-plugin-checker: specifier: ~0.6.4 - version: 0.6.4(eslint@8.57.0)(stylelint@16.2.1)(typescript@5.4.3)(vite@5.2.2)(vue-tsc@1.8.27) + version: 0.6.4(eslint@8.57.0)(stylelint@16.2.1)(typescript@5.4.3)(vite@5.2.4)(vue-tsc@1.8.27) vite-plugin-inspect: specifier: ^0.8.3 - version: 0.8.3(vite@5.2.2) + version: 0.8.3(vite@5.2.4) vite-plugin-mkcert: specifier: ^1.17.5 - version: 1.17.5(vite@5.2.2) + version: 1.17.5(vite@5.2.4) vite-plugin-svg-icons: specifier: ~2.0.1 - version: 2.0.1(vite@5.2.2) + version: 2.0.1(vite@5.2.4) vue-eslint-parser: specifier: ~9.4.2 version: 9.4.2(eslint@8.57.0) vue-tsc: specifier: ~1.8.27 version: 1.8.27(typescript@5.4.3) + dependenciesMeta: + '@admin-pkg/vite-plugin-msw': + injected: true + '@admin-pkg/vite-plugin-tinymce-resource': + injected: true packages/components: dependencies: @@ -2575,7 +2580,6 @@ packages: is-node-process: 1.2.0 outvariant: 1.4.2 strict-event-emitter: 0.5.1 - dev: false /@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1: resolution: {integrity: sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==} @@ -3506,7 +3510,7 @@ packages: resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} dev: true - /@unocss/astro@0.58.6(vite@5.2.2): + /@unocss/astro@0.58.6(vite@5.2.4): resolution: {integrity: sha512-0BvbhEp5Ln6wFNnhISusB2hcfycWkdgnjlFMcLT69efvj4G39MzB6JYT/1qiidLfpj35HcqkpBz7TfZ4bUmOAw==} peerDependencies: vite: ^2.9.0 || ^3.0.0-0 || ^4.0.0 || ^5.0.0-0 @@ -3516,8 +3520,8 @@ packages: dependencies: '@unocss/core': 0.58.6 '@unocss/reset': 0.58.6 - '@unocss/vite': 0.58.6(vite@5.2.2) - vite: 5.2.2(@types/node@20.11.30)(less@4.2.0) + '@unocss/vite': 0.58.6(vite@5.2.4) + vite: 5.2.4(@types/node@20.11.30)(less@4.2.0) transitivePeerDependencies: - rollup dev: true @@ -3700,7 +3704,7 @@ packages: '@unocss/core': 0.58.6 dev: true - /@unocss/vite@0.58.6(vite@5.2.2): + /@unocss/vite@0.58.6(vite@5.2.4): resolution: {integrity: sha512-DPXCoYU/Ozqc/Jeptd41XvtW8MSgVxmtTyhpMAsm/hJuBfwIV7Fy3TZquf4V9BpaTb4ao1LVXzgXmVUmj2HXpA==} peerDependencies: vite: ^2.9.0 || ^3.0.0-0 || ^4.0.0 || ^5.0.0-0 @@ -3715,12 +3719,12 @@ packages: chokidar: 3.6.0 fast-glob: 3.3.2 magic-string: 0.30.8 - vite: 5.2.2(@types/node@20.11.30)(less@4.2.0) + vite: 5.2.4(@types/node@20.11.30)(less@4.2.0) transitivePeerDependencies: - rollup dev: true - /@vitejs/plugin-vue-jsx@3.1.0(vite@5.2.2)(vue@3.4.21): + /@vitejs/plugin-vue-jsx@3.1.0(vite@5.2.4)(vue@3.4.21): resolution: {integrity: sha512-w9M6F3LSEU5kszVb9An2/MmXNxocAnUb3WhRr8bHlimhDrXNt6n6D2nJQR3UXpGlZHh/EsgouOHCsM8V3Ln+WA==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: @@ -3730,20 +3734,20 @@ packages: '@babel/core': 7.24.3 '@babel/plugin-transform-typescript': 7.24.1(@babel/core@7.24.3) '@vue/babel-plugin-jsx': 1.2.2(@babel/core@7.24.3) - vite: 5.2.2(@types/node@20.11.30)(less@4.2.0) + vite: 5.2.4(@types/node@20.11.30)(less@4.2.0) vue: 3.4.21(typescript@5.4.3) transitivePeerDependencies: - supports-color dev: true - /@vitejs/plugin-vue@5.0.4(vite@5.2.2)(vue@3.4.21): + /@vitejs/plugin-vue@5.0.4(vite@5.2.4)(vue@3.4.21): resolution: {integrity: sha512-WS3hevEszI6CEVEx28F8RjTX97k3KsrcY6kvTg7+Whm5y3oYvcqzVeGCU3hxSAn4uY2CLCkeokkGKpoctccilQ==} engines: {node: ^18.0.0 || >=20.0.0} peerDependencies: vite: ^5.0.0 vue: ^3.2.25 dependencies: - vite: 5.2.2(@types/node@20.11.30)(less@4.2.0) + vite: 5.2.4(@types/node@20.11.30)(less@4.2.0) vue: 3.4.21(typescript@5.4.3) dev: true @@ -8501,6 +8505,37 @@ packages: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} dev: true + /msw@2.2.10(typescript@5.4.3): + resolution: {integrity: sha512-OQhHBocUsI8j+czCTRouGCGYE8pk6hq8HQ0HFg9mYQg7KCzqVpUSbMikmRbRXGoid28FFvYqjbxB3/UWw50VZQ==} + engines: {node: '>=18'} + hasBin: true + requiresBuild: true + peerDependencies: + typescript: '>= 4.7.x' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@bundled-es-modules/cookie': 2.0.0 + '@bundled-es-modules/statuses': 1.0.1 + '@inquirer/confirm': 3.1.0 + '@mswjs/cookies': 1.1.0 + '@mswjs/interceptors': 0.25.16 + '@open-draft/until': 2.1.0 + '@types/cookie': 0.6.0 + '@types/statuses': 2.0.5 + chalk: 4.1.2 + graphql: 16.8.1 + headers-polyfill: 4.0.3 + is-node-process: 1.2.0 + outvariant: 1.4.2 + path-to-regexp: 6.2.1 + strict-event-emitter: 0.5.1 + type-fest: 4.13.1 + typescript: 5.4.3 + yargs: 17.7.2 + dev: true + /msw@2.2.9(typescript@5.4.3): resolution: {integrity: sha512-MLIFufBe6m9c5rZKlmGl6jl1pjn7cTNiDGEgn5v2iVRs0mz+neE2r7lRyYNzvcp6FbdiUEIRp/Y2O2gRMjO8yQ==} engines: {node: '>=18'} @@ -8530,6 +8565,7 @@ packages: type-fest: 4.13.1 typescript: 5.4.3 yargs: 17.7.2 + dev: false /muggle-string@0.3.1: resolution: {integrity: sha512-ckmWDJjphvd/FvZawgygcUeQCxzvohjFO5RxTjj4eq8kw359gFF3E1brjfI+viLMxss5JrHTDRHZvu2/tuy0Qg==} @@ -11385,7 +11421,7 @@ packages: engines: {node: '>= 10.0.0'} dev: true - /unocss@0.58.6(postcss@8.4.38)(vite@5.2.2): + /unocss@0.58.6(postcss@8.4.38)(vite@5.2.4): resolution: {integrity: sha512-HBstDtC6KKD5yCYh5hHpPdHGZai0B/iLlDwkOIK+xfQYrvl8tNBvKfRz3xgiaI5MJ+fLmEOxbfXQIjleU1A0iA==} engines: {node: '>=14'} peerDependencies: @@ -11397,7 +11433,7 @@ packages: vite: optional: true dependencies: - '@unocss/astro': 0.58.6(vite@5.2.2) + '@unocss/astro': 0.58.6(vite@5.2.4) '@unocss/cli': 0.58.6 '@unocss/core': 0.58.6 '@unocss/extractor-arbitrary-variants': 0.58.6 @@ -11416,8 +11452,8 @@ packages: '@unocss/transformer-compile-class': 0.58.6 '@unocss/transformer-directives': 0.58.6 '@unocss/transformer-variant-group': 0.58.6 - '@unocss/vite': 0.58.6(vite@5.2.2) - vite: 5.2.2(@types/node@20.11.30)(less@4.2.0) + '@unocss/vite': 0.58.6(vite@5.2.4) + vite: 5.2.4(@types/node@20.11.30)(less@4.2.0) transitivePeerDependencies: - postcss - rollup @@ -11534,7 +11570,7 @@ packages: vfile-message: 2.0.4 dev: true - /vite-plugin-checker@0.6.4(eslint@8.57.0)(stylelint@16.2.1)(typescript@5.4.3)(vite@5.2.2)(vue-tsc@1.8.27): + /vite-plugin-checker@0.6.4(eslint@8.57.0)(stylelint@16.2.1)(typescript@5.4.3)(vite@5.2.4)(vue-tsc@1.8.27): resolution: {integrity: sha512-2zKHH5oxr+ye43nReRbC2fny1nyARwhxdm0uNYp/ERy4YvU9iZpNOsueoi/luXw5gnpqRSvjcEPxXbS153O2wA==} engines: {node: '>=14.16'} peerDependencies: @@ -11579,7 +11615,7 @@ packages: stylelint: 16.2.1(typescript@5.4.3) tiny-invariant: 1.3.3 typescript: 5.4.3 - vite: 5.2.2(@types/node@20.11.30)(less@4.2.0) + vite: 5.2.4(@types/node@20.11.30)(less@4.2.0) vscode-languageclient: 7.0.0 vscode-languageserver: 7.0.0 vscode-languageserver-textdocument: 1.0.11 @@ -11587,7 +11623,7 @@ packages: vue-tsc: 1.8.27(typescript@5.4.3) dev: true - /vite-plugin-inspect@0.8.3(vite@5.2.2): + /vite-plugin-inspect@0.8.3(vite@5.2.4): resolution: {integrity: sha512-SBVzOIdP/kwe6hjkt7LSW4D0+REqqe58AumcnCfRNw4Kt3mbS9pEBkch+nupu2PBxv2tQi69EQHQ1ZA1vgB/Og==} engines: {node: '>=14'} peerDependencies: @@ -11606,13 +11642,13 @@ packages: perfect-debounce: 1.0.0 picocolors: 1.0.0 sirv: 2.0.4 - vite: 5.2.2(@types/node@20.11.30)(less@4.2.0) + vite: 5.2.4(@types/node@20.11.30)(less@4.2.0) transitivePeerDependencies: - rollup - supports-color dev: true - /vite-plugin-mkcert@1.17.5(vite@5.2.2): + /vite-plugin-mkcert@1.17.5(vite@5.2.4): resolution: {integrity: sha512-KKGY3iHx/9zb7ow8JJ+nLN2HiNIBuPBwj34fJ+jAJT89/8qfk7msO7G7qipR8VDEm9xMCys0xT11QOJbZcg3/Q==} engines: {node: '>=v16.7.0'} peerDependencies: @@ -11622,12 +11658,12 @@ packages: axios: 1.6.8(debug@4.3.4) debug: 4.3.4 picocolors: 1.0.0 - vite: 5.2.2(@types/node@20.11.30)(less@4.2.0) + vite: 5.2.4(@types/node@20.11.30)(less@4.2.0) transitivePeerDependencies: - supports-color dev: true - /vite-plugin-svg-icons@2.0.1(vite@5.2.2): + /vite-plugin-svg-icons@2.0.1(vite@5.2.4): resolution: {integrity: sha512-6ktD+DhV6Rz3VtedYvBKKVA2eXF+sAQVaKkKLDSqGUfnhqXl3bj5PPkVTl3VexfTuZy66PmINi8Q6eFnVfRUmA==} peerDependencies: vite: '>=2.0.0' @@ -11640,7 +11676,7 @@ packages: pathe: 0.2.0 svg-baker: 1.7.0 svgo: 2.8.0 - vite: 5.2.2(@types/node@20.11.30)(less@4.2.0) + vite: 5.2.4(@types/node@20.11.30)(less@4.2.0) transitivePeerDependencies: - supports-color dev: true @@ -11681,6 +11717,43 @@ packages: optionalDependencies: fsevents: 2.3.3 + /vite@5.2.4(@types/node@20.11.30)(less@4.2.0): + resolution: {integrity: sha512-vjFghvHWidBTinu5TCymJk/lRHlR5ljqB83yugr0HA1xspUPdOZHqbqDLnZ8f9/jINrtFHTCYYyIUi+o+Q5iyg==} + engines: {node: ^18.0.0 || >=20.0.0} + hasBin: true + peerDependencies: + '@types/node': ^18.0.0 || >=20.0.0 + less: '*' + lightningcss: ^1.21.0 + sass: '*' + stylus: '*' + sugarss: '*' + terser: ^5.4.0 + peerDependenciesMeta: + '@types/node': + optional: true + less: + optional: true + lightningcss: + optional: true + sass: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + dependencies: + '@types/node': 20.11.30 + esbuild: 0.20.2 + less: 4.2.0 + postcss: 8.4.38 + rollup: 4.13.0 + optionalDependencies: + fsevents: 2.3.3 + dev: true + /vscode-jsonrpc@6.0.0: resolution: {integrity: sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==} engines: {node: '>=8.0.0 || >=10.0.0'} @@ -12178,3 +12251,26 @@ packages: /zwitch@1.0.5: resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==} dev: true + + file:packages/vite-plugin-msw(msw@2.2.10): + resolution: {directory: packages/vite-plugin-msw, type: directory} + id: file:packages/vite-plugin-msw + name: '@admin-pkg/vite-plugin-msw' + peerDependencies: + msw: ^2.0.0 + dependencies: + '@mswjs/interceptors': 0.26.8 + headers-polyfill: 4.0.3 + msw: 2.2.10(typescript@5.4.3) + strict-event-emitter: 0.5.1 + dev: true + + file:packages/vite-plugin-tinymce-resource(vite@5.2.4): + resolution: {directory: packages/vite-plugin-tinymce-resource, type: directory} + id: file:packages/vite-plugin-tinymce-resource + name: '@admin-pkg/vite-plugin-tinymce-resource' + peerDependencies: + vite: ^5.0.0 + dependencies: + vite: 5.2.4(@types/node@20.11.30)(less@4.2.0) + dev: true diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 000000000..9231f59bc --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,26 @@ +import { promisify } from 'node:util'; +import { exec } from 'node:child_process'; + +// TODO 此脚本用于临时解决:https://github.com/pnpm/pnpm/issues/6088 + +const execAsync = promisify(exec); + +const executeCommand = async (cmd) => { + try { + const { stdout, stderr } = await execAsync(cmd); + console.log('标准输出:', stdout); + stderr && console.error('标准错误:', stderr); + } catch (error) { + console.error('执行命令时出错:', error); + } +}; + +if (process.env.POSTINSTALL_EXECUTED === 'true') { + // console.log('执行过了'); +} else { + // console.log('首次执行'); + process.env.POSTINSTALL_EXECUTED = 'true'; + + await executeCommand('pnpm nx:build'); + await executeCommand('pnpm install'); +} diff --git a/vite.config.ts b/vite.config.ts index 53b6e13f0..10089b923 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -110,6 +110,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { server: { host: '0.0.0.0', port: 8088, + open: true, proxy: { '/api': { target: 'https://nest-api.buqiyuan.site', @@ -125,6 +126,12 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { rewrite: (path) => path.replace(new RegExp(`^/upload`), ''), }, }, + // 提前转换和缓存文件以进行预热。可以在服务器启动时提高初始页面加载速度,并防止转换瀑布。 + warmup: { + // 请注意,只应该预热频繁使用的文件,以免在启动时过载 Vite 开发服务器 + // 可以通过运行 npx vite --debug transform 并检查日志来找到频繁使用的文件 + clientFiles: ['./index.html', './src/{components,api}/*'], + }, }, optimizeDeps: { include: ['lodash-es', 'ant-design-vue/es/locale/zh_CN', 'ant-design-vue/es/locale/en_US'],