Skip to content

Commit

Permalink
docs: twoslash cut does not take effect (#16466)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed Apr 19, 2024
1 parent 6a127d6 commit e7adcf0
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,24 +259,26 @@ experimental: {

If the hashed assets and public files aren't deployed together, options for each group can be defined independently using asset `type` included in the second `context` param given to the function.

<!-- prettier-ignore-start -->
```ts twoslash
import type { UserConfig } from 'vite'
import path from 'node:path'
const config: UserConfig = {
// ---cut-before---
experimental: {
renderBuiltUrl(filename, { hostId, hostType, type }) {
if (type === 'public') {
return 'https://www.domain.com/' + filename
} else if (path.extname(hostId) === '.js') {
return { runtime: `window.__assetsPath(${JSON.stringify(filename)})` }
} else {
return 'https://cdn.domain.com/assets/' + filename
}
},
// ---cut-before---
experimental: {
renderBuiltUrl(filename, { hostId, hostType, type }) {
if (type === 'public') {
return 'https://www.domain.com/' + filename
} else if (path.extname(hostId) === '.js') {
return { runtime: `window.__assetsPath(${JSON.stringify(filename)})` }
} else {
return 'https://cdn.domain.com/assets/' + filename
}
},
// ---cut-after---
},
// ---cut-after---
}
```
<!-- prettier-ignore-end -->

Note that the `filename` passed is a decoded URL, and if the function returns a URL string, it should also be decoded. Vite will handle the encoding automatically when rendering the URLs. If an object with `runtime` is returned, encoding should be handled yourself where needed as the runtime code will be rendered as is.

0 comments on commit e7adcf0

Please sign in to comment.