Skip to content

Commit

Permalink
docs: note url string must be static (#7508)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Mar 29, 2022
1 parent 93ae8e5 commit b7cc0dc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions docs/guide/assets.md
Expand Up @@ -103,8 +103,13 @@ function getImageUrl(name) {
}
```
During the production build, Vite will perform necessary transforms so that the URLs still point to the correct location even after bundling and asset hashing.
During the production build, Vite will perform necessary transforms so that the URLs still point to the correct location even after bundling and asset hashing. However, the URL string must be static so it can be analyzed, otherwise the code will be left as is, which can cause runtime errors if `build.target` does not support `import.meta.url`
::: warning Note: Does not work with SSR
```js
// Vite will not transform this
const imgUrl = new URL(imagePath, import.meta.url).href
```
::: warning Does not work with SSR
This pattern does not work if you are using Vite for Server-Side Rendering, because `import.meta.url` have different semantics in browsers vs. Node.js. The server bundle also cannot determine the client host URL ahead of time.
:::

0 comments on commit b7cc0dc

Please sign in to comment.