diff --git a/guide/api-environment-plugins.md b/guide/api-environment-plugins.md index 3cd27d3a..dd67b55e 100644 --- a/guide/api-environment-plugins.md +++ b/guide/api-environment-plugins.md @@ -126,6 +126,29 @@ interface HotUpdateOptions { } ``` +## 插件中的基于环境的状态 {#per-environment-state-in-plugins} + +鉴于相同的插件实例会被用于不同的环境,插件的状态需要以 `this.environment` 作为键来存储。这与生态系统中已使用的模式相同,即使用 `ssr` 布尔值作为键来避免混合客户端和 SSR 模块状态的方式。可以使用 `Map` 来分别为每个环境保存其对应的状态。注意:为了保持向后兼容性,在未设置 `perEnvironmentStartEndDuringDev: true` 标志时,`buildStart` 和 `buildEnd` 仅会针对客户端环境被调用。 + +```js +function PerEnvironmentCountTransformedModulesPlugin() { + const state = new Map() + return { + name: 'count-transformed-modules', + perEnvironmentStartEndDuringDev: true, + buildStart() { + state.set(this.environment, { count: 0 }) + }, + transform(id) { + state.get(this.environment).count++ + }, + buildEnd() { + console.log(this.environment.name, state.get(this.environment).count) + } + } +} +``` + ## 基于环境的插件 {#per-environment-plugins} 插件可以使用 `applyToEnvironment` 函数来定义它适用的环境。 diff --git a/package.json b/package.json index cc2621e2..aa27bcb0 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "feed": "^5.1.0", "vitepress": "^1.6.3", "vitepress-plugin-group-icons": "^1.6.0", - "vue": "^3.5.16", + "vue": "^3.5.17", "@types/node": "^20.9.2", "@type-challenges/utils": "^0.1.1", "chalk": "^4.1.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 63950d2d..ad4b7024 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,13 +40,13 @@ importers: version: 6.3.0-beta.0(@types/node@20.12.12) vitepress: specifier: ^1.6.3 - version: 1.6.3(@algolia/client-search@5.20.0)(@types/node@20.12.12)(postcss@8.5.3)(search-insights@2.13.0)(typescript@5.4.5) + version: 1.6.3(@algolia/client-search@5.20.0)(@types/node@20.12.12)(postcss@8.5.6)(search-insights@2.13.0)(typescript@5.4.5) vitepress-plugin-group-icons: specifier: ^1.6.0 version: 1.6.0(markdown-it@14.1.0)(vite@6.3.0-beta.0(@types/node@20.12.12)) vue: - specifier: ^3.5.16 - version: 3.5.16(typescript@5.4.5) + specifier: ^3.5.17 + version: 3.5.17(typescript@5.4.5) yorkie: specifier: ^2.0.0 version: 2.0.0 @@ -144,10 +144,19 @@ packages: engines: {node: '>=6.0.0'} hasBin: true + '@babel/parser@7.27.5': + resolution: {integrity: sha512-OsQd175SxWkGlzbny8J3K8TnnDD0N3lrIUtB92xwyRpzaenGZhxDvxN/JgU00U3CDZNj9tPuDJ5H0WS4Nt3vKg==} + engines: {node: '>=6.0.0'} + hasBin: true + '@babel/types@7.27.1': resolution: {integrity: sha512-+EzkxvLNfiUeKMgy/3luqfsCWFRXLb7U6wNQTk60tovuckwB15B191tJWvpp4HjiQWdJkCxO3Wbvc6jlk3Xb2Q==} engines: {node: '>=6.9.0'} + '@babel/types@7.27.6': + resolution: {integrity: sha512-ETyHEk2VHHvl9b9jZP5IHPavHYk57EhanlRRuae9XCpb/j5bDCbPPMOBfCWhnl/7EDJz0jEMCi/RhccCE8r1+Q==} + engines: {node: '>=6.9.0'} + '@docsearch/css@3.8.2': resolution: {integrity: sha512-y05ayQFyUmCXze79+56v/4HpycYF3uFqB78pLPrSV5ZKAlDuIAAJNhaRi8tTdRNXh05yxX/TyNnzD6LwSM89vQ==} @@ -823,20 +832,20 @@ packages: '@vue/compiler-core@3.5.15': resolution: {integrity: sha512-nGRc6YJg/kxNqbv/7Tg4juirPnjHvuVdhcmDvQWVZXlLHjouq7VsKmV1hIxM/8yKM0VUfwT/Uzc0lO510ltZqw==} - '@vue/compiler-core@3.5.16': - resolution: {integrity: sha512-AOQS2eaQOaaZQoL1u+2rCJIKDruNXVBZSiUD3chnUrsoX5ZTQMaCvXlWNIfxBJuU15r1o7+mpo5223KVtIhAgQ==} + '@vue/compiler-core@3.5.17': + resolution: {integrity: sha512-Xe+AittLbAyV0pabcN7cP7/BenRBNcteM4aSDCtRvGw0d9OL+HG1u/XHLY/kt1q4fyMeZYXyIYrsHuPSiDPosA==} '@vue/compiler-dom@3.5.15': resolution: {integrity: sha512-ZelQd9n+O/UCBdL00rlwCrsArSak+YLZpBVuNDio1hN3+wrCshYZEDUO3khSLAzPbF1oQS2duEoMDUHScUlYjA==} - '@vue/compiler-dom@3.5.16': - resolution: {integrity: sha512-SSJIhBr/teipXiXjmWOVWLnxjNGo65Oj/8wTEQz0nqwQeP75jWZ0n4sF24Zxoht1cuJoWopwj0J0exYwCJ0dCQ==} + '@vue/compiler-dom@3.5.17': + resolution: {integrity: sha512-+2UgfLKoaNLhgfhV5Ihnk6wB4ljyW1/7wUIog2puUqajiC29Lp5R/IKDdkebh9jTbTogTbsgB+OY9cEWzG95JQ==} - '@vue/compiler-sfc@3.5.16': - resolution: {integrity: sha512-rQR6VSFNpiinDy/DVUE0vHoIDUF++6p910cgcZoaAUm3POxgNOOdS/xgoll3rNdKYTYPnnbARDCZOyZ+QSe6Pw==} + '@vue/compiler-sfc@3.5.17': + resolution: {integrity: sha512-rQQxbRJMgTqwRugtjw0cnyQv9cP4/4BxWfTdRBkqsTfLOHWykLzbOc3C4GGzAmdMDxhzU/1Ija5bTjMVrddqww==} - '@vue/compiler-ssr@3.5.16': - resolution: {integrity: sha512-d2V7kfxbdsjrDSGlJE7my1ZzCXViEcqN6w14DOsDrUCHEA6vbnVCpRFfrc4ryCP/lCKzX2eS1YtnLE/BuC9f/A==} + '@vue/compiler-ssr@3.5.17': + resolution: {integrity: sha512-hkDbA0Q20ZzGgpj5uZjb9rBzQtIHLS78mMilwrlpWk2Ep37DYntUz0PonQ6kr113vfOEdM+zTBuJDaceNIW0tQ==} '@vue/compiler-vue2@2.7.16': resolution: {integrity: sha512-qYC3Psj9S/mfu9uVi5WvNZIzq+xnXMhOwbTFKKDD7b1lhpnn71jXSFdTQ+WsIEk0ONCd7VV2IMm7ONl6tbQ86A==} @@ -858,19 +867,19 @@ packages: typescript: optional: true - '@vue/reactivity@3.5.16': - resolution: {integrity: sha512-FG5Q5ee/kxhIm1p2bykPpPwqiUBV3kFySsHEQha5BJvjXdZTUfmya7wP7zC39dFuZAcf/PD5S4Lni55vGLMhvA==} + '@vue/reactivity@3.5.17': + resolution: {integrity: sha512-l/rmw2STIscWi7SNJp708FK4Kofs97zc/5aEPQh4bOsReD/8ICuBcEmS7KGwDj5ODQLYWVN2lNibKJL1z5b+Lw==} - '@vue/runtime-core@3.5.16': - resolution: {integrity: sha512-bw5Ykq6+JFHYxrQa7Tjr+VSzw7Dj4ldR/udyBZbq73fCdJmyy5MPIFR9IX/M5Qs+TtTjuyUTCnmK3lWWwpAcFQ==} + '@vue/runtime-core@3.5.17': + resolution: {integrity: sha512-QQLXa20dHg1R0ri4bjKeGFKEkJA7MMBxrKo2G+gJikmumRS7PTD4BOU9FKrDQWMKowz7frJJGqBffYMgQYS96Q==} - '@vue/runtime-dom@3.5.16': - resolution: {integrity: sha512-T1qqYJsG2xMGhImRUV9y/RseB9d0eCYZQ4CWca9ztCuiPj/XWNNN+lkNBuzVbia5z4/cgxdL28NoQCvC0Xcfww==} + '@vue/runtime-dom@3.5.17': + resolution: {integrity: sha512-8El0M60TcwZ1QMz4/os2MdlQECgGoVHPuLnQBU3m9h3gdNRW9xRmI8iLS4t/22OQlOE6aJvNNlBiCzPHur4H9g==} - '@vue/server-renderer@3.5.16': - resolution: {integrity: sha512-BrX0qLiv/WugguGsnQUJiYOE0Fe5mZTwi6b7X/ybGB0vfrPH9z0gD/Y6WOR1sGCgX4gc25L1RYS5eYQKDMoNIg==} + '@vue/server-renderer@3.5.17': + resolution: {integrity: sha512-BOHhm8HalujY6lmC3DbqF6uXN/K00uWiEeF22LfEsm9Q93XeJ/plHTepGwf6tqFcF7GA5oGSSAAUock3VvzaCA==} peerDependencies: - vue: 3.5.16 + vue: 3.5.17 '@vue/shared@3.5.13': resolution: {integrity: sha512-/hnE/qP5ZoGpol0a5mDi45bOd7t3tjYJBjsgCsivow7D48cJeV5l05RD82lPqi7gRiphZM37rnhW1l6ZoCNNnQ==} @@ -878,8 +887,8 @@ packages: '@vue/shared@3.5.15': resolution: {integrity: sha512-bKvgFJJL1ZX9KxMCTQY6xD9Dhe3nusd1OhyOb1cJYGqvAr0Vg8FIjHPMOEVbJ9GDT9HG+Bjdn4oS8ohKP8EvoA==} - '@vue/shared@3.5.16': - resolution: {integrity: sha512-c/0fWy3Jw6Z8L9FmTyYfkpM5zklnqqa9+a6dz3DvONRKW2NEbh46BP0FHuLFSWi2TnQEtp91Z6zOWNrU6QiyPg==} + '@vue/shared@3.5.17': + resolution: {integrity: sha512-CabR+UN630VnsJO/jHWYBC1YVXyMq94KKp6iF5MQgZJs5I8cmjw6oVMO1oDbtBkENSHSSn/UadWlW/OAgdmKrg==} '@vueuse/core@12.7.0': resolution: {integrity: sha512-jtK5B7YjZXmkGNHjviyGO4s3ZtEhbzSgrbX+s5o+Lr8i2nYqNyHuPVOeTdM1/hZ5Tkxg/KktAuAVDDiHMraMVA==} @@ -1366,6 +1375,10 @@ packages: resolution: {integrity: sha512-dle9A3yYxlBSrt8Fu+IpjGT8SY8hN0mlaA6GY8t0P5PjIOZemULz/E2Bnm/2dcUOena75OTNkHI76uZBNUUq3A==} engines: {node: ^10 || ^12 || >=14} + postcss@8.5.6: + resolution: {integrity: sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==} + engines: {node: ^10 || ^12 || >=14} + preact@10.22.0: resolution: {integrity: sha512-RRurnSjJPj4rp5K6XoP45Ui33ncb7e4H7WiOHVpjbkvqvA3U+N8Z6Qbo0AE6leGYBV66n8EhEaFixvIu3SkxFw==} @@ -1620,8 +1633,8 @@ packages: peerDependencies: vue: ^3.0.0 - vue@3.5.16: - resolution: {integrity: sha512-rjOV2ecxMd5SiAmof2xzh2WxntRcigkX/He4YFJ6WdRvVUrbt6DxC1Iujh10XLl8xCDRDtGKMeO3D+pRQ1PP9w==} + vue@3.5.17: + resolution: {integrity: sha512-LbHV3xPN9BeljML+Xctq4lbz2lVHCR6DtbpTf5XIO6gugpXUN49j2QQPcMj086r9+AkJ0FfUT8xjulKKBkkr9g==} peerDependencies: typescript: '*' peerDependenciesMeta: @@ -1768,11 +1781,20 @@ snapshots: dependencies: '@babel/types': 7.27.1 + '@babel/parser@7.27.5': + dependencies: + '@babel/types': 7.27.6 + '@babel/types@7.27.1': dependencies: '@babel/helper-string-parser': 7.27.1 '@babel/helper-validator-identifier': 7.27.1 + '@babel/types@7.27.6': + dependencies: + '@babel/helper-string-parser': 7.27.1 + '@babel/helper-validator-identifier': 7.27.1 + '@docsearch/css@3.8.2': {} '@docsearch/js@3.8.2(@algolia/client-search@5.20.0)(search-insights@2.13.0)': @@ -2189,14 +2211,14 @@ snapshots: '@shikijs/vitepress-twoslash@2.5.0(typescript@5.4.5)': dependencies: '@shikijs/twoslash': 3.0.0(typescript@5.4.5) - floating-vue: 5.2.2(vue@3.5.16(typescript@5.4.5)) + floating-vue: 5.2.2(vue@3.5.17(typescript@5.4.5)) mdast-util-from-markdown: 2.0.2 mdast-util-gfm: 3.1.0 mdast-util-to-hast: 13.2.0 shiki: 2.5.0 twoslash: 0.2.12(typescript@5.4.5) twoslash-vue: 0.2.12(typescript@5.4.5) - vue: 3.5.16(typescript@5.4.5) + vue: 3.5.17(typescript@5.4.5) transitivePeerDependencies: - '@nuxt/kit' - supports-color @@ -2291,10 +2313,10 @@ snapshots: '@ungap/structured-clone@1.2.0': {} - '@vitejs/plugin-vue@5.2.1(vite@5.4.14(@types/node@20.12.12))(vue@3.5.16(typescript@5.4.5))': + '@vitejs/plugin-vue@5.2.1(vite@5.4.14(@types/node@20.12.12))(vue@3.5.17(typescript@5.4.5))': dependencies: vite: 5.4.14(@types/node@20.12.12) - vue: 3.5.16(typescript@5.4.5) + vue: 3.5.17(typescript@5.4.5) '@volar/language-core@2.4.1': dependencies: @@ -2310,10 +2332,10 @@ snapshots: estree-walker: 2.0.2 source-map-js: 1.2.1 - '@vue/compiler-core@3.5.16': + '@vue/compiler-core@3.5.17': dependencies: - '@babel/parser': 7.27.2 - '@vue/shared': 3.5.16 + '@babel/parser': 7.27.5 + '@vue/shared': 3.5.17 entities: 4.5.0 estree-walker: 2.0.2 source-map-js: 1.2.1 @@ -2323,27 +2345,27 @@ snapshots: '@vue/compiler-core': 3.5.15 '@vue/shared': 3.5.15 - '@vue/compiler-dom@3.5.16': + '@vue/compiler-dom@3.5.17': dependencies: - '@vue/compiler-core': 3.5.16 - '@vue/shared': 3.5.16 + '@vue/compiler-core': 3.5.17 + '@vue/shared': 3.5.17 - '@vue/compiler-sfc@3.5.16': + '@vue/compiler-sfc@3.5.17': dependencies: - '@babel/parser': 7.27.2 - '@vue/compiler-core': 3.5.16 - '@vue/compiler-dom': 3.5.16 - '@vue/compiler-ssr': 3.5.16 - '@vue/shared': 3.5.16 + '@babel/parser': 7.27.5 + '@vue/compiler-core': 3.5.17 + '@vue/compiler-dom': 3.5.17 + '@vue/compiler-ssr': 3.5.17 + '@vue/shared': 3.5.17 estree-walker: 2.0.2 magic-string: 0.30.17 - postcss: 8.5.3 + postcss: 8.5.6 source-map-js: 1.2.1 - '@vue/compiler-ssr@3.5.16': + '@vue/compiler-ssr@3.5.17': dependencies: - '@vue/compiler-dom': 3.5.16 - '@vue/shared': 3.5.16 + '@vue/compiler-dom': 3.5.17 + '@vue/shared': 3.5.17 '@vue/compiler-vue2@2.7.16': dependencies: @@ -2381,40 +2403,40 @@ snapshots: optionalDependencies: typescript: 5.4.5 - '@vue/reactivity@3.5.16': + '@vue/reactivity@3.5.17': dependencies: - '@vue/shared': 3.5.16 + '@vue/shared': 3.5.17 - '@vue/runtime-core@3.5.16': + '@vue/runtime-core@3.5.17': dependencies: - '@vue/reactivity': 3.5.16 - '@vue/shared': 3.5.16 + '@vue/reactivity': 3.5.17 + '@vue/shared': 3.5.17 - '@vue/runtime-dom@3.5.16': + '@vue/runtime-dom@3.5.17': dependencies: - '@vue/reactivity': 3.5.16 - '@vue/runtime-core': 3.5.16 - '@vue/shared': 3.5.16 + '@vue/reactivity': 3.5.17 + '@vue/runtime-core': 3.5.17 + '@vue/shared': 3.5.17 csstype: 3.1.3 - '@vue/server-renderer@3.5.16(vue@3.5.16(typescript@5.4.5))': + '@vue/server-renderer@3.5.17(vue@3.5.17(typescript@5.4.5))': dependencies: - '@vue/compiler-ssr': 3.5.16 - '@vue/shared': 3.5.16 - vue: 3.5.16(typescript@5.4.5) + '@vue/compiler-ssr': 3.5.17 + '@vue/shared': 3.5.17 + vue: 3.5.17(typescript@5.4.5) '@vue/shared@3.5.13': {} '@vue/shared@3.5.15': {} - '@vue/shared@3.5.16': {} + '@vue/shared@3.5.17': {} '@vueuse/core@12.7.0(typescript@5.4.5)': dependencies: '@types/web-bluetooth': 0.0.20 '@vueuse/metadata': 12.7.0 '@vueuse/shared': 12.7.0(typescript@5.4.5) - vue: 3.5.16(typescript@5.4.5) + vue: 3.5.17(typescript@5.4.5) transitivePeerDependencies: - typescript @@ -2422,7 +2444,7 @@ snapshots: dependencies: '@vueuse/core': 12.7.0(typescript@5.4.5) '@vueuse/shared': 12.7.0(typescript@5.4.5) - vue: 3.5.16(typescript@5.4.5) + vue: 3.5.17(typescript@5.4.5) optionalDependencies: focus-trap: 7.6.4 transitivePeerDependencies: @@ -2432,7 +2454,7 @@ snapshots: '@vueuse/shared@12.7.0(typescript@5.4.5)': dependencies: - vue: 3.5.16(typescript@5.4.5) + vue: 3.5.17(typescript@5.4.5) transitivePeerDependencies: - typescript @@ -2613,11 +2635,11 @@ snapshots: dependencies: xml-js: 1.6.11 - floating-vue@5.2.2(vue@3.5.16(typescript@5.4.5)): + floating-vue@5.2.2(vue@3.5.17(typescript@5.4.5)): dependencies: '@floating-ui/dom': 1.1.1 - vue: 3.5.16(typescript@5.4.5) - vue-resize: 2.0.0-alpha.1(vue@3.5.16(typescript@5.4.5)) + vue: 3.5.17(typescript@5.4.5) + vue-resize: 2.0.0-alpha.1(vue@3.5.17(typescript@5.4.5)) focus-trap@7.6.4: dependencies: @@ -3038,6 +3060,12 @@ snapshots: picocolors: 1.1.1 source-map-js: 1.2.1 + postcss@8.5.6: + dependencies: + nanoid: 3.3.11 + picocolors: 1.1.1 + source-map-js: 1.2.1 + preact@10.22.0: {} property-information@6.5.0: {} @@ -3276,7 +3304,7 @@ snapshots: transitivePeerDependencies: - supports-color - vitepress@1.6.3(@algolia/client-search@5.20.0)(@types/node@20.12.12)(postcss@8.5.3)(search-insights@2.13.0)(typescript@5.4.5): + vitepress@1.6.3(@algolia/client-search@5.20.0)(@types/node@20.12.12)(postcss@8.5.6)(search-insights@2.13.0)(typescript@5.4.5): dependencies: '@docsearch/css': 3.8.2 '@docsearch/js': 3.8.2(@algolia/client-search@5.20.0)(search-insights@2.13.0) @@ -3285,7 +3313,7 @@ snapshots: '@shikijs/transformers': 2.5.0 '@shikijs/types': 2.3.0 '@types/markdown-it': 14.1.2 - '@vitejs/plugin-vue': 5.2.1(vite@5.4.14(@types/node@20.12.12))(vue@3.5.16(typescript@5.4.5)) + '@vitejs/plugin-vue': 5.2.1(vite@5.4.14(@types/node@20.12.12))(vue@3.5.17(typescript@5.4.5)) '@vue/devtools-api': 7.7.1 '@vue/shared': 3.5.13 '@vueuse/core': 12.7.0(typescript@5.4.5) @@ -3295,9 +3323,9 @@ snapshots: minisearch: 7.1.1 shiki: 2.3.0 vite: 5.4.14(@types/node@20.12.12) - vue: 3.5.16(typescript@5.4.5) + vue: 3.5.17(typescript@5.4.5) optionalDependencies: - postcss: 8.5.3 + postcss: 8.5.6 transitivePeerDependencies: - '@algolia/client-search' - '@types/node' @@ -3325,17 +3353,17 @@ snapshots: - typescript - universal-cookie - vue-resize@2.0.0-alpha.1(vue@3.5.16(typescript@5.4.5)): + vue-resize@2.0.0-alpha.1(vue@3.5.17(typescript@5.4.5)): dependencies: - vue: 3.5.16(typescript@5.4.5) + vue: 3.5.17(typescript@5.4.5) - vue@3.5.16(typescript@5.4.5): + vue@3.5.17(typescript@5.4.5): dependencies: - '@vue/compiler-dom': 3.5.16 - '@vue/compiler-sfc': 3.5.16 - '@vue/runtime-dom': 3.5.16 - '@vue/server-renderer': 3.5.16(vue@3.5.16(typescript@5.4.5)) - '@vue/shared': 3.5.16 + '@vue/compiler-dom': 3.5.17 + '@vue/compiler-sfc': 3.5.17 + '@vue/runtime-dom': 3.5.17 + '@vue/server-renderer': 3.5.17(vue@3.5.17(typescript@5.4.5)) + '@vue/shared': 3.5.17 optionalDependencies: typescript: 5.4.5