Skip to content

Commit 43e9116

Browse files
[v6] deprecate import.meta.env.ASSETS_PREFIX (#12468)
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
1 parent 824ae0d commit 43e9116

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/content/docs/en/guides/environment-variables.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ Astro includes a few environment variables out of the box:
5858
- `import.meta.env.DEV`: `true` if your site is running in development; `false` otherwise. Always the opposite of `import.meta.env.PROD`.
5959
- `import.meta.env.BASE_URL`: The base URL your site is being served from. This is determined by the [`base` config option](/en/reference/configuration-reference/#base).
6060
- `import.meta.env.SITE`: This is set to [the `site` option](/en/reference/configuration-reference/#site) specified in your project's `astro.config`.
61-
- `import.meta.env.ASSETS_PREFIX`: The prefix for Astro-generated asset links if the [`build.assetsPrefix` config option](/en/reference/configuration-reference/#buildassetsprefix) is set. This can be used to create asset links not handled by Astro.
6261

6362
Use them like any other environment variable.
6463

src/content/docs/en/guides/upgrade-to/v6.mdx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ The following deprecated features are no longer supported and are no longer docu
105105

106106
Some deprecated features may temporarily continue to function until they are completely removed. Others may silently have no effect, or throw an error prompting you to update your code.
107107

108-
### `Astro` in `getStaticPaths()`
108+
### Deprecated: `Astro` in `getStaticPaths()`
109109

110110
<SourcePR number="14432" title="feat: deprecate Astro in getStaticPaths"/>
111111

@@ -131,6 +131,28 @@ export async function getStaticPaths() {
131131

132132
<ReadMore>Read more about [built-in environment variables such as `import.meta.env.SITE`](/en/guides/environment-variables/#default-environment-variables) that are accessible when [using `getStaticPaths()` to dynamically generate static routes](/en/guides/routing/#static-ssg-mode).</ReadMore>
133133

134+
### Deprecated: `import.meta.env.ASSETS_PREFIX`
135+
136+
<SourcePR number="14461" title="feat: deprecate import.meta.env.ASSETS_PREFIX"/>
137+
138+
In Astro 5.x, it was possible to access `build.assetsPrefix` in your Astro config via the built-in environment variable `import.meta.env.ASSETS_PREFIX`. However, Astro v5.7.0 introduced the `astro:config` virtual model to expose a non-exhaustive, serializable, type-safe version of the Astro configuration which included access to `build.assetsPrefix` directly. This became the preferred way to access the prefix for Astro-generated asset links when set, although the environment variable still existed.
139+
140+
Astro 6.0 deprecates this variable in favor of `build.assetsPrefix` from the `astro:config/server` module.
141+
142+
#### What should I do?
143+
144+
Replace any occurances of `import.meta.env.ASSETS_PREFIX` with the `build.assetsPrefix` import from `astro:config/server`. This is a drop-in replacement to provide the existing value, and no other changes to your code should be necessary:
145+
146+
```ts del={4} ins={2,5}
147+
import { someLogic } from "./utils"
148+
import { build } from "astro:config/server"
149+
150+
someLogic(import.meta.env.ASSETS_PREFIX)
151+
someLogic(build.assetsPrefix)
152+
```
153+
154+
<ReadMore>Read more about the [`astro:config` virtual modules](/en/reference/modules/astro-config/).</ReadMore>
155+
134156
## Removed
135157

136158
The following features have now been entirely removed from the code base and can no longer be used. Some of these features may have continued to work in your project even after deprecation. Others may have silently had no effect.

0 commit comments

Comments
 (0)