Skip to content

Commit 55a1a91

Browse files
feat: deprecate import.meta.env.ASSETS_PREFIX (#14461)
Co-authored-by: Matt Kane <m@mk.gg>
1 parent 117f22e commit 55a1a91

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

.changeset/green-garlics-heal.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'astro': major
3+
---
4+
5+
Deprecates `import.meta.env.ASSETS_PREFIX`
6+
7+
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.
8+
9+
Astro 6.0 deprecates this variable in favor of `build.assetsPrefix` from the `astro:config/server` module.
10+
11+
#### What should I do?
12+
13+
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:
14+
15+
```diff
16+
import { someLogic } from "./utils"
17+
+import { build } from "astro:config/server"
18+
19+
-someLogic(import.meta.env.ASSETS_PREFIX)
20+
+someLogic(build.assetsPrefix)
21+
```

packages/astro/client.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
/// <reference path="./types/fonts.d.ts" />
66

77
interface ImportMetaEnv {
8+
// TODO: remove in Astro 7
89
/**
910
* The prefix for Astro-generated asset links if the build.assetsPrefix config option is set. This can be used to create asset links not handled by Astro.
11+
* @deprecated This will be removed in a future major version of Astro. Use `build.assetsPrefix` from `astro:config/server` instead.
1012
*/
1113
readonly ASSETS_PREFIX: string | Record<string, string>;
1214
/**

0 commit comments

Comments
 (0)