Skip to content

Commit 2484dc4

Browse files
Princesseuhsarah11918kanashimia
authored
config: remove ~/assets alias (#8113)
Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Mia Kanashi <[email protected]>
1 parent 4967c69 commit 2484dc4

File tree

13 files changed

+68
-24
lines changed

13 files changed

+68
-24
lines changed

.changeset/clever-bats-breathe.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'astro': major
3+
---
4+
5+
This import alias is no longer included by default with astro:assets. If you were using this alias with experimental assets, you must convert them to relative file paths, or create your own [import aliases](https://docs.astro.build/en/guides/aliases/).
6+
7+
```diff
8+
---
9+
// src/pages/posts/post-1.astro
10+
- import rocket from '~/assets/rocket.png'
11+
+ import rocket from '../../assets/rocket.png';
12+
---
13+
```

packages/astro/src/assets/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export type LocalImageProps<T> = ImageSharedProps<T> & {
9090
*
9191
* **Example**:
9292
* ```js
93-
* import myImage from "~/assets/my_image.png";
93+
* import myImage from "../assets/my_image.png";
9494
* ```
9595
* And then refer to the image, like so:
9696
* ```astro

packages/astro/src/assets/vite-plugin-assets.ts

-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import MagicString from 'magic-string';
2-
import { fileURLToPath } from 'node:url';
32
import type * as vite from 'vite';
43
import { normalizePath } from 'vite';
54
import type { AstroPluginOptions, ImageTransform } from '../@types/astro';
@@ -31,18 +30,6 @@ export default function assets({
3130
// Expose the components and different utilities from `astro:assets` and handle serving images from `/_image` in dev
3231
{
3332
name: 'astro:assets',
34-
config() {
35-
return {
36-
resolve: {
37-
alias: [
38-
{
39-
find: /^~\/assets\/(.+)$/,
40-
replacement: fileURLToPath(new URL('./assets/$1', settings.config.srcDir)),
41-
},
42-
],
43-
},
44-
};
45-
},
4633
async resolveId(id) {
4734
if (id === VIRTUAL_SERVICE_ID) {
4835
return await this.resolve(settings.config.image.service.entrypoint);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"alt": "Futuristic landscape with chrome buildings and blue skies",
3-
"src": "~/assets/the-future.jpg"
3+
"src": "../../assets/the-future.jpg"
44
}

packages/astro/test/fixtures/core-image-base/src/content/blog/one.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: One
3-
image: ~/assets/penguin2.jpg
3+
image: ../../assets/penguin2.jpg
44
cover:
55
image: ../../assets/penguin1.jpg
66
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "astro/tsconfigs/base",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"~/assets/*": ["src/assets/*"]
7+
},
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "astro/tsconfigs/base",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"~/assets/*": ["src/assets/*"]
7+
},
8+
}
9+
}

packages/astro/test/fixtures/core-image/src/content/blog/one.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: One
3-
image: ~/assets/penguin2.jpg
3+
image: ../../assets/penguin2.jpg
44
cover:
55
image: ../../assets/penguin1.jpg
66
arrayOfImages:
7-
- ~/assets/penguin2.jpg
8-
- ~/assets/penguin1.jpg
7+
- ../../assets/penguin2.jpg
8+
- ../../assets/penguin1.jpg
99
refinedImage: ../../assets/penguin1.jpg
1010
---
1111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "astro/tsconfigs/base",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"~/assets/*": ["src/assets/*"]
7+
},
8+
}
9+
}

packages/astro/tsconfigs/base.json

-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
"esModuleInterop": true,
2424
// Skip typechecking libraries and .d.ts files
2525
"skipLibCheck": true,
26-
// Add alias for assets folder for easy reference to assets
27-
"baseUrl": ".",
28-
"paths": {
29-
"~/assets/*": ["src/assets/*"]
30-
},
3126
// Allow JavaScript files to be imported
3227
"allowJs": true
3328
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "astro/tsconfigs/base",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"~/assets/*": ["src/assets/*"]
7+
},
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "astro/tsconfigs/base",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"~/assets/*": ["src/assets/*"]
7+
},
8+
}
9+
}

pnpm-lock.yaml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)