Skip to content

Commit

Permalink
fix(issues): #668 #671 #672 #673
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcego committed May 25, 2024
1 parent a7a58ba commit d535a0e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
9 changes: 5 additions & 4 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default defineConfig({
['meta', { property: 'og:image', content: ogImage }],
['meta', { property: 'og:url', content: ogUrl }],
['meta', { property: 'og:description', content: ogDescription }],
['meta', { property: 'og:site_name', content: 'vitejs' }],
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
['meta', { name: 'twitter:site', content: '@vite_js' }],
['meta', { name: 'theme-color', content: '#646cff' }],
Expand Down Expand Up @@ -375,10 +376,10 @@ export default defineConfig({
.replace(/\/index\.md$/, '/')
.replace(/\.md$/, '/')
pageData.frontmatter.head ??= []
pageData.frontmatter.head.unshift([
'link',
{ rel: 'canonical', href: canonicalUrl },
])
pageData.frontmatter.head.unshift(
['link', { rel: 'canonical', href: canonicalUrl }],
['meta', { property: 'og:title', content: pageData.title }],
)
return pageData
},
markdown: {
Expand Down
19 changes: 8 additions & 11 deletions docs/guide/api-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ interface HtmlTagDescriptor {

```js
handleHotUpdate({ server, modules, timestamp }) {
// También usar `server.ws.send` para admitir Vite <5.1 si es necesario
server.hot.send({ type: 'full-reload' })
server.ws.send({ type: 'full-reload' })
// Invalidar módulos manualmente
const invalidatedModules = new Set()
for (const mod of modules) {
Expand All @@ -443,8 +442,7 @@ interface HtmlTagDescriptor {

```js
handleHotUpdate({ server }) {
// También usar `server.ws.send` para admitir Vite <5.1 si es necesario
server.hot.send({
server.ws.send({
type: 'custom',
event: 'special-update',
data: {}
Expand All @@ -453,7 +451,7 @@ interface HtmlTagDescriptor {
}
```

El código del cliente debe registrar el controlador correspondiente utilizando la [APi HMR](./api-hmr) (esto podría inyectarse mediante el hook `transform` del mismo complemento):
El código del cliente debe registrar el controlador correspondiente utilizando la [API HMR](./api-hmr) (esto podría inyectarse mediante el hook `transform` del mismo complemento):

```js
if (import.meta.hot) {
Expand Down Expand Up @@ -551,7 +549,7 @@ Desde Vite 2.9, proporcionamos algunas utilidades para complementos que ayudan a
### Servidor a Cliente
En el lado del complemento, podríamos usar `server.hot.send` (a partir de Vite 5.1) o `server.ws.send` para transmitir eventos a todos los clientes:
En el lado del complemento, podríamos usar `server.ws.send` para transmitir eventos al cliente:
```js
// vite.config.js
Expand All @@ -560,9 +558,8 @@ export default defineConfig({
{
// ...
configureServer(server) {
// Ejemplo: espera a que un cliente se conecte antes de enviar un mensaje
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 @@ -598,7 +595,7 @@ if (import.meta.hot) {
}
```
Luego usar `server.hot.on` (a partir de Vite 5.1) o `server.ws.on` y escuchar los eventos en el lado del servidor:
Luego usa `server.ws.on` y así escuchar los eventos en el lado del servidor:
```js
// vite.config.js
Expand All @@ -607,7 +604,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
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"docs-serve": "vitepress serve"
},
"devDependencies": {
"@shikijs/vitepress-twoslash": "^1.5.1",
"@shikijs/vitepress-twoslash": "^1.6.0",
"@types/express": "^4.17.21",
"vitepress": "1.1.4",
"vitepress": "1.2.0",
"vue": "^3.4.27"
}
}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,34 @@
"@types/fs-extra": "^11.0.4",
"@types/less": "^3.0.6",
"@types/micromatch": "^4.0.7",
"@types/node": "^20.12.11",
"@types/node": "^20.12.12",
"@types/picomatch": "^2.3.3",
"@types/semver": "^7.5.8",
"@types/stylus": "^0.48.42",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"@vitejs/release-scripts": "^1.3.1",
"conventional-changelog-cli": "^4.1.0",
"eslint": "^8.57.0",
"eslint-define-config": "^2.1.0",
"eslint-plugin-i": "^2.29.1",
"eslint-plugin-n": "^17.6.0",
"eslint-plugin-n": "^17.7.0",
"eslint-plugin-regexp": "^2.5.0",
"execa": "^8.0.1",
"execa": "^9.1.0",
"feed": "^4.2.2",
"fs-extra": "^11.2.0",
"lint-staged": "^15.2.2",
"npm-run-all2": "^6.1.2",
"picocolors": "^1.0.0",
"npm-run-all2": "^6.2.0",
"picocolors": "^1.0.1",
"playwright-chromium": "^1.44.0",
"prettier": "3.2.5",
"rimraf": "^5.0.5",
"rimraf": "^5.0.7",
"rollup": "^4.13.0",
"semver": "^7.6.0",
"semver": "^7.6.2",
"simple-git-hooks": "^2.11.1",
"tslib": "^2.6.2",
"tsx": "^4.10.0",
"tsx": "^4.10.5",
"typescript": "^5.2.2",
"unbuild": "^2.0.0",
"vite": "latest",
Expand Down

0 comments on commit d535a0e

Please sign in to comment.