Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions docs/changes/hotupdate-hook.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# HMR `hotUpdate` Plugin Hook
# هوک پلاگین `hotUpdate` برای HMR

::: tip Feedback
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
::: tip بازخورد
به ما در [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358) بازخورد دهید
:::

We're planning to deprecate the `handleHotUpdate` plugin hook in favor of [`hotUpdate` hook](/guide/api-environment#the-hotupdate-hook) to be [Environment API](/guide/api-environment.md) aware, and handle additional watch events with `create` and `delete`.
ما قصد داریم هوک پلاگین `handleHotUpdate` را به نفع [هوک `hotUpdate`](/guide/api-environment#the-hotupdate-hook) منسوخ کنیم تا با [API محیطی](/guide/api-environment.md) هماهنگ شود و رویدادهای اضافی نظلرت (watch events) را با create و delete مدیریت کند.

Affected scope: `Vite Plugin Authors`
دامنه تاثیر: `نویسندگان پلاگین Vite`

::: warning Future Deprecation
`hotUpdate` was first introduced in `v6.0`. The deprecation of `handleHotUpdate` is planned for `v7.0`. We don't yet recommend moving away from `handleHotUpdate` yet. If you want to experiment and give us feedback, you can use the `future.removePluginHookHandleHotUpdate` to `"warn"` in your vite config.
::: warning منسوخ‌شدن در آینده
هوک `hotUpdate` اولین بار در نسخه `v6.0` معرفی شد. منسوخ شدن `handleHotUpdate` برای نسخه `v7.0` برنامه‌ریزی شده است. هنوز توصیه نمی‌کنیم که از `handleHotUpdate` استفاده نکنید. اگر می‌خواهید آزمایش کنید و بازخورد بدهید، می‌توانید در تنظیمات Vite خود `future.removePluginHookHandleHotUpdate` را به مقدار `"warn"` تنظیم کنید.
:::

## Motivation
## انگیزه

The [`handleHotUpdate` hook](/guide/api-plugin.md#handlehotupdate) allows to perform custom HMR update handling. A list of modules to be updated is passed in the `HmrContext`
[هوک `handleHotUpdate`](/guide/api-plugin.md#handlehotupdate) به شما این امکان را می‌دهد که به‌طور سفارشی به‌روزرسانی‌های HMR را مدیریت کنید. یک لیست از ماژول‌هایی که باید به‌روزرسانی شوند در `HmrContext` ارسال می‌شود.

```ts
interface HmrContext {
Expand All @@ -26,9 +26,9 @@ interface HmrContext {
}
```

This hook is called once for all environments, and the passed modules have mixed information from the Client and SSR environments only. Once frameworks move to custom environments, a new hook that is called for each of them is needed.
این هوک یک‌بار برای تمامی محیط‌ها فراخوانی می‌شود و ماژول‌های ارسال‌شده اطلاعات ترکیبی از محیط‌های Client و SSR دارند. زمانی که فریم‌ورک‌ها به محیط‌های سفارشی منتقل شوند، به هوک جدیدی نیاز است که برای هر یک از این محیط‌ها فراخوانی شود.

The new `hotUpdate` hook works in the same way as `handleHotUpdate` but it is called for each environment and receives a new `HotUpdateOptions` instance:
هوک جدید `hotUpdate` به همان روش `handleHotUpdate` کار می‌کند، اما برای هر محیط به‌طور جداگانه فراخوانی می‌شود و یک نمونه جدید از `HotUpdateOptions` دریافت می‌کند.

```ts
interface HotUpdateOptions {
Expand All @@ -41,31 +41,32 @@ interface HotUpdateOptions {
}
```

The current dev environment can be accessed like in other Plugin hooks with `this.environment`. The `modules` list will now be module nodes from the current environment only. Each environment update can define different update strategies.
محیط توسعه کنونی مانند سایر هوک‌های پلاگین با استفاده از `this.environment` قابل دسترسی است. لیست `modules` اکنون تنها شامل گره‌های ماژول از محیط جاری خواهد بود. هر به‌روزرسانی محیط می‌تواند استراتژی‌های به‌روزرسانی مختلفی را تعریف کند.

This hook is also now called for additional watch events and not only for `'update'`. Use `type` to differentiate between them.

## Migration Guide
این هوک اکنون برای رویدادهای اضافی نظارت (watch events) نیز فراخوانی می‌شود و تنها مختص `'update'` نیست. برای تمایز بین آن‌ها از `type` استفاده کنید.

Filter and narrow down the affected module list so that the HMR is more accurate.
## راهنمای مهاجرت

برای دقت بیشتر در HMR، لیست ماژول‌های تحت تاثیر را فیلتر کرده و محدود کنید.

```js
handleHotUpdate({ modules }) {
return modules.filter(condition)
}

// Migrate to:
// مهاجرت کنید به:

hotUpdate({ modules }) {
return modules.filter(condition)
}
```

Return an empty array and perform a full reload:
یک آرایه خالی برگردانید و بارگذاری کامل را انجام دهید:

```js
handleHotUpdate({ server, modules, timestamp }) {
// Invalidate modules manually
// ماژول‌ها را به‌صورت دستی غیرفعال کنید
const invalidatedModules = new Set()
for (const mod of modules) {
server.moduleGraph.invalidateModule(
Expand All @@ -79,10 +80,10 @@ handleHotUpdate({ server, modules, timestamp }) {
return []
}

// Migrate to:
// مهاجرت کنید به:

hotUpdate({ modules, timestamp }) {
// Invalidate modules manually
// ماژول‌ها را به‌صورت دستی غیرفعال کنید
const invalidatedModules = new Set()
for (const mod of modules) {
this.environment.moduleGraph.invalidateModule(
Expand All @@ -97,7 +98,7 @@ hotUpdate({ modules, timestamp }) {
}
```

Return an empty array and perform complete custom HMR handling by sending custom events to the client:
یک آرایه خالی برگردانید و مدیریت کامل HMR سفارشی را با ارسال رویدادهای سفارشی به کلاینت انجام دهید:

```js
handleHotUpdate({ server }) {
Expand All @@ -109,7 +110,7 @@ handleHotUpdate({ server }) {
return []
}

// Migrate to...
// مهاجرت کنید به:

hotUpdate() {
this.environment.hot.send({
Expand Down
32 changes: 16 additions & 16 deletions docs/changes/index.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# Breaking Changes
# تغییرات اساسی

List of breaking changes in Vite including API deprecations, removals, and changes. Most of the changes below can be opt-in using the [`future` option](/config/shared-options.html#future) in your Vite config.
لیست تغییرات اساسی در Vite شامل منسوخ شدن API‌ها، حذف‌ها، و تغییرات. بیشتر تغییرات زیر را می‌توانید با استفاده از [گزینه `آینده`](/config/shared-options.html#future) در تنظیمات Vite خود به‌صورت اختیاری فعال کنید.

## Planned
## برنامه‌ریزی شده

These changes are planned for the next major version of Vite. The deprecation or usage warnings will guide you where possible, and we're reaching out to framework, plugin authors, and users to apply these changes.
این تغییرات برای نسخه اصلی بعدی Vite برنامه‌ریزی شده‌اند. هشدارهای مربوط به منسوخ شدن یا استفاده در صورت امکان شما را راهنمایی خواهند کرد و ما با نویسندگان فریم‌ورک‌ها، افزونه‌ها و کاربران در ارتباط هستیم تا این تغییرات را اعمال کنیم.

- _No planned changes yet_
- _هنوز هیچ تغییر برنامه‌ریزی شده‌ای وجود ندارد_

## Considering
## قابل توجه

These changes are being considered and are often experimental APIs that intend to improve upon current usage patterns. As not all changes are listed here, please check out the [Experimental Label in Vite GitHub Discussions](https://github.com/vitejs/vite/discussions/categories/feedback?discussions_q=label%3Aexperimental+category%3AFeedback) for the full list.
این تغییرات در حال بررسی هستند و اغلب شامل API‌های آزمایشی می‌باشند که هدف آن‌ها بهبود الگوهای استفاده فعلی است. از آنجا که تمامی تغییرات در اینجا ذکر نشده‌اند، لطفاً برای مشاهده لیست کامل به [Experimental Label in Vite GitHub Discussions](https://github.com/vitejs/vite/discussions/categories/feedback?discussions_q=label%3Aexperimental+category%3AFeedback) مراجعه کنید.

We don't recommend switching to these APIs yet. They are included in Vite to help us gather feedback. Please check these proposals and let us know how they work in your use case in each's linked GitHub Discussions.
ما توصیه نمی‌کنیم که هنوز به این API‌ها سوئیچ کنید. این API‌ها در Vite گنجانده شده‌اند تا به ما در جمع‌آوری بازخورد کمک کنند. لطفاً این پیشنهادها را بررسی کنید و در بحث‌های مرتبط در GitHub به ما اطلاع دهید که چگونه در موارد استفاده شما کار می‌کنند.

- [`this.environment` in Hooks](/changes/this-environment-in-hooks)
- [HMR `hotUpdate` Plugin Hook](/changes/hotupdate-hook)
- [Move to per-environment APIs](/changes/per-environment-apis)
- [SSR using `ModuleRunner` API](/changes/ssr-using-modulerunner)
- [Shared plugins during build](/changes/shared-plugins-during-build)
- [`this.environment` در هوک‌ها](/changes/this-environment-in-hooks)
- [هوک پلاگین `hotUpdate`برای HMR](/changes/hotupdate-hook)
- [انتقال به API‌های مخصوص هر محیط](/changes/per-environment-apis)
- [SSR با استفاده از `ModuleRunner` API](/changes/ssr-using-modulerunner)
- [اشتراک‌گذاری پلاگین‌ها در حین ساخت (build)](/changes/shared-plugins-during-build)

## Past
## گذشته

The changes below has been done or reverted. They are no longer relevant in the current major version.
تغییرات زیر اعمال شده یا لغو گردیده‌اند. این تغییرات در نسخه اصلی فعلی دیگر مرتبط نیستند.

- _No past changes yet_
- _هنوز هیچ تغییر گذشته‌ای وجود ندارد_
28 changes: 14 additions & 14 deletions docs/changes/this-environment-in-hooks.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# `this.environment` in Hooks
# `this.environment` در هوک‌ها

::: tip Feedback
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
::: tip بازخورد
به ما در [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358) بازخورد دهید
:::

Before Vite 6, only two environments were available: `client` and `ssr`. A single `options.ssr` plugin hook argument in `resolveId`, `load` and `transform` allowed plugin authors to differentiate between these two environments when processing modules in plugin hooks. In Vite 6, a Vite application can define any number of named environments as needed. We're introducing `this.environment` in the plugin context to interact with the environment of the current module in hooks.
پیش از Vite 6، فقط دو محیط موجود بود: `client` و `ssr`. یک آرگومان هوک پلاگین `options.ssr` در `resolveId`، `load` و `transform` به نویسندگان پلاگین این امکان را می‌داد که هنگام پردازش ماژول‌ها در هوک‌های پلاگین، این دو محیط را از هم تمایز دهند. در Vite 6، یک برنامه Vite می‌تواند هر تعداد محیط نام‌گذاری‌شده را طبق نیاز تعریف کند. ما `this.environment` را در زمینه پلاگین معرفی می‌کنیم تا با محیط ماژول جاری در هوک‌ها تعامل داشته باشیم.

Affect scope: `Vite Plugin Authors`
دامنه تاثیر: `نویسندگان پلاگین Vite`

::: warning Future Deprecation
`this.environment` was introduced in `v6.0`. The deprecation of `options.ssr` is planned for `v7.0`. At that point we'll start recommending migrating your plugins to use the new API. To identify your usage, set `future.removePluginHookSsrArgument` to `"warn"` in your vite config.
::: warning منسوخ‌شدن در آینده
`this.environment` در نسخه `v6.0` معرفی‌شد. منسوخ شدن `options.ssr` برای نسخه `v7.0` برنامه‌ریزی شده است. در آن زمان، شروع به توصیه به مهاجرت پلاگین‌ها به استفاده از API جدید خواهیم کرد. برای شناسایی استفاده از این ویژگی، می‌توانید `future.removePluginHookSsrArgument` را در تنظیمات Vite خود به مقدار `"warn"` تنظیم کنید.
:::

## Motivation
## انگیزه

`this.environment` not only allow the plugin hook implementation to know the current environment name, it also gives access to the environment config options, module graph information, and transform pipeline (`environment.config`, `environment.moduleGraph`, `environment.transformRequest()`). Having the environment instance available in the context allows plugin authors to avoid the dependency of the whole dev server (typically cached at startup through the `configureServer` hook).
`this.environment` نه تنها به پیاده‌سازی هوک پلاگین اجازه می‌دهد که نام محیط جاری را بداند، بلکه دسترسی به گزینه‌های پیکربندی محیط، اطلاعات گراف ماژول، و خط لوله تبدیل (transform pipeline) را نیز فراهم می‌کند (`environment.config`، `environment.moduleGraph`، `environment.transformRequest `). در دسترس بودن نمونه محیط در زمینه پلاگین به نویسندگان پلاگین این امکان را می‌دهد که از وابستگی به سرور توسعه کامل (که معمولاً از طریق هوک `configureServer` در ابتدای راه‌اندازی کش می‌شود) جلوگیری کنند.

## Migration Guide
## راهنمای مهاجرت

For the existing plugin to do a quick migration, replace the `options.ssr` argument with `this.environment.name !== 'client'` in the `resolveId`, `load` and `transform` hooks:
برای انجام یک مهاجرت سریع در پلاگین‌های موجود، آرگومان `options.ssr` را با `this.environment.name !== 'client'` در هوک‌های `resolveId`، `load` و `transform` جایگزین کنید:

```ts
import { Plugin } from 'vite'
Expand All @@ -31,13 +31,13 @@ export function myPlugin(): Plugin {
const isSSR = this.environment.name !== 'client' // [!code ++]

if (isSSR) {
// SSR specific logic
// منطق خاص SSR
} else {
// Client specific logic
// منطق خاص Client
}
},
}
}
```

For a more robust long term implementation, the plugin hook should handle for [multiple environments](/guide/api-environment.html#accessing-the-current-environment-in-hooks) using fine-grained environment options instead of relying on the environment name.
برای یک پیاده‌سازی پایدارتر در بلندمدت، هوک پلاگین باید به جای تکیه بر نام محیط، به‌طور دقیق برای [چندین محیط](/guide/api-environment.html#accessing-the-current-environment-in-hooks) از گزینه‌های محیطی ریزدانه استفاده کند.
Loading