Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed May 24, 2024
2 parents 87bbb04 + e7d38ab commit 09a032e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/release-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ jobs:
- name: Get pkgName for tag
id: tag
run: |
# skip if alpha
if [[ $GITHUB_REF_NAME =~ alpha ]]; then
exit 0
fi
# matching v2.0.0 / v2.0.0-beta.8 etc
if [[ $GITHUB_REF_NAME =~ ^v.+ ]]; then
pkgName="vite"
Expand All @@ -31,6 +36,8 @@ jobs:
echo "pkgName=$pkgName" >> $GITHUB_OUTPUT
- name: Create Release for Tag
# only run if tag is not alpha
if: steps.tag.outputs.pkgName
id: release_tag
uses: yyx990803/release-tag@master
env:
Expand Down
17 changes: 7 additions & 10 deletions docs/guide/api-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo

```js
handleHotUpdate({ server, modules, timestamp }) {
// Also use `server.ws.send` to support Vite <5.1 if needed
server.hot.send({ type: 'full-reload' })
server.ws.send({ type: 'full-reload' })
// Invalidate modules manually
const invalidatedModules = new Set()
for (const mod of modules) {
Expand All @@ -448,8 +447,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo

```js
handleHotUpdate({ server }) {
// Also use `server.ws.send` to support Vite <5.1 if needed
server.hot.send({
server.ws.send({
type: 'custom',
event: 'special-update',
data: {}
Expand Down Expand Up @@ -556,7 +554,7 @@ Since Vite 2.9, we provide some utilities for plugins to help handle the communi

### Server to Client

On the plugin side, we could use `server.hot.send` (since Vite 5.1) or `server.ws.send` to broadcast events to all the clients:
On the plugin side, we could use `server.ws.send` to broadcast events to the client:

```js
// vite.config.js
Expand All @@ -565,9 +563,8 @@ export default defineConfig({
{
// ...
configureServer(server) {
// Example: wait for a client to connect before sending a message
server.hot.on('connection', () => {
server.hot.send('my:greetings', { msg: 'hello' })
server.ws.on('connection', () => {
server.ws.send('my:greetings', { msg: 'hello' })
})
},
},
Expand Down Expand Up @@ -603,7 +600,7 @@ if (import.meta.hot) {
}
```

Then use `server.hot.on` (since Vite 5.1) or `server.ws.on` and listen to the events on the server side:
Then use `server.ws.on` and listen to the events on the server side:

```js
// vite.config.js
Expand All @@ -612,7 +609,7 @@ export default defineConfig({
{
// ...
configureServer(server) {
server.hot.on('my:from-client', (data, client) => {
server.ws.on('my:from-client', (data, client) => {
console.log('Message from client:', data.msg) // Hey!
// reply only to the client (if needed)
client.send('my:ack', { msg: 'Hi! I got your message!' })
Expand Down
15 changes: 13 additions & 2 deletions packages/vite/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,19 @@ export interface Plugin<A = any> extends RollupPlugin<A> {

/**
* @deprecated
* Compat support, ctx.modules is a backward compatible ModuleNode array
* with the mixed client and ssr moduleGraph. Use hotUpdate instead
* Perform custom handling of HMR updates.
* The handler receives a context containing changed filename, timestamp, a
* list of modules affected by the file change, and the dev server instance.
*
* - The hook can return a filtered list of modules to narrow down the update.
* e.g. for a Vue SFC, we can narrow down the part to update by comparing
* the descriptors.
*
* - The hook can also return an empty array and then perform custom updates
* by sending a custom hmr payload via server.ws.send().
*
* - If the hook doesn't return a value, the hmr update will be performed as
* normal.
*/
handleHotUpdate?: ObjectHook<
(
Expand Down

0 comments on commit 09a032e

Please sign in to comment.