Hello,
I am using Sage 10.0.0-beta.2 and I have some trouble using assets. I didn’t modify bud.config.js except the proxy:
I have followed the documentation to use images in my templates:
<img src="@asset('images/example.jpg')">
But it doesn’t work. I need to write the following:
<img src="@asset('assets/images/example.jpg')">
Moreover, I have modified the proxy to see them on http://localhost:3000/:
.proxy({
url: "https://original.url.of.my.local.dev",
replace: {
href: true,
window: true,
publicPath: false
}
})
My questions are:
why Bud copies images in a subfolder named assets? Can I modify this?
why fonts are not copied in public directory?
Have a great day.
Best Regards,
4 Likes
I’m having a similar problem.
I’m putting my images on resources/images
folder, and trying to use on my CSS as this:
.background {
background-image: url("../images/background.svg");
}
In the same wey that is in the documentation .
It works after running yarn build
, but not while running rand dev
, neither on the live preview http://localhost:3000/
nor on http://localhost:3000/
, the images doesn’t load, because the browser is trying to load them on a different directory.
1 Like
ben
December 27, 2021, 4:01pm
3
Confirming the OP’s behavior is a bug /cc @kellymears @QWp6t
Unable to reproduce @jasaldivara ’s issue (images referenced from CSS are working as expected via yarn build
and yarn dev
)
ben
December 28, 2021, 3:22pm
4
Forgot to mention regarding the fonts issue, @kellymears has a workaround here you can use before the next Bud release: Sage: url() in @font-face declaration doesn't work · Issue #822 · roots/bud · GitHub
Thank you! Font icons work now (I didn’t read the workaround, I was waiting for an official release)
(I have a typo on my previuos comment. It should say yarn dev
instead of rand dev
. Not sure how can I edit that.)
Turns out I had a bad proxy configuration on my bud.config.js
. I was using only my hostname, instead of the full site url (since that was how it worked on a previous dev version before beta 2). Once I configured correctly the proxy, my images loaded both on yarn build
and yarn dev
.
I’m still noticing something strange: Background images don’t load on my ‘normal’ (non live) site while i’m running yarn dev
. I have to stop yarn dev
and run yarn build
for the images to load. I’m not sure if this is considered a bug.
I also have noticed another strange behavior. When adding the line .assets(['resources/images'])
to my bud.config.js
, the images are saved in public/assets/images
, but images refrenced on CSS are saved in public/assets
. So if I keep that line on bud.config.js
, the images are duplicated on two different directories. For me, the easy solution is to just omit that line from my config file.
I’m having a similar issue, when referencing images in css using yarn dev
:
Example: background-image: url(’…/images/music.svg’);
It’s emitting the absolute url of the current page: http://localhost:3000/questions/qa-title-speaker-name-here/assets/music.svg;
Rather than the root directory: http://localhost:10004/wp-content/themes/changesource/public/assets/images/question_2.jpeg
When using yarn build
however, the images are emitted correctly:
http://localhost:10004/wp-content/themes/changesource/public/assets/images/question_2.ede033.jpeg
ben
December 29, 2021, 3:49pm
9
Please provide some code so I can drop it on my theme for testing
ben
December 29, 2021, 4:39pm
10
Filed a bug on the Bud repo for anyone who wants to follow for the @asset
issue
opened 04:38PM - 29 Dec 21 UTC
bug
@roots/sage
### Terms
- [X] I have read the [guidelines for Contributing to Roots Projects]… (https://github.com/roots/.github/blob/master/CONTRIBUTING.md)
- [X] This request is not a duplicate of an existing issue
- [X] I have read the [docs](https://roots.io/docs/) and followed them (if applicable)
- [X] I have seached the [Roots Discourse](https://discourse.roots.io/) for answers and followed them (if applicable)
- [X] This is not a personal support request that should be posted on the [Roots Discourse](https://discourse.roots.io/) community
### Description
#### What's wrong?
Sage 10's [`@asset`](https://roots.io/docs/sage/10.x/compiling-assets/#theme-assets) directive isn't referencing assets from the correct directories
#### What have you tried?
`<img src="@asset('images/example.jpg')">`
#### What insights have you gained?
Bud's `public` directory throws the assets into an `assets/` subdirectory
#### Temporary workarounds
`<img src="@asset('assets/images/example.jpg')">`
### Steps To Reproduce
1. From a Sage 10 theme, place an image in `resources/images/`
1. Run `yarn build`
1. Try to use the `@asset` directive as documented/expected
### Expected Behavior
The asset directive should load the asset
### Actual Behavior
The asset can't be found
### Relevant Log Output
_No response_
### Versions
v5
Noted and I’m not sure why there’s an extra dot here, only two in my code.
Is this default path for beta 2: ../images/image.jpeg
?
ben
December 29, 2021, 7:35pm
12
Yep that’s correct
Is your local dev URL http://localhost:10004/
? That probably needs to be a host without a port to work correctly?
Sorry for the delay
This is the code from my scss (SASS) file:
.teaser,
.teaser-secundario {
display: flex;
flex-direction: column;
.thumbnail {
flex-grow: 1;
img {
height: 100%;
object-fit: cover;
}
}
.encabezado {
background-color: teal;
color: white;
background-size: cover;
background-position: left center;
text-align: center;
:link,
:visited {
color: white;
}
&.verde {
background-color: #5f9f48;
background-image: url("../images/encabezado_verde.svg");
}
&.naranja {
background-color: #fe8709;
background-image: url("../images/encabezado_amarillo.svg");
}
&.rosa {
background-color: #f01e5b;
background-image: url("../images/encabezado_rosa.svg");
}
}
h3 {
font-size: 1.15rem;
}
h4 {
font-size: 1rem;
}
}
This is the code from my blade template:
@if ( $query_destacadas->have_posts() )
<div class="teaser">
@php ( $query_destacadas->the_post())
<div class="thumbnail">
<a href="{{ wp_get_shortlink() }}">
{!! get_the_post_thumbnail() !!}
</a>
</div>
<h3 class="encabezado verde">
<a href="{{ wp_get_shortlink() }}">
{{ the_title('', '', false ) }}
</a>
</h3>
</div>
@endif
This is what I see on Google Chrome developer tools when inspecting h3.encabezado
after running yarn build
(background image is loading correclty):
.teaser-secundario .encabezado.verde, .teaser .encabezado.verde {
background-color: #5f9f48;
background-image: url(assets/encabezado_verde.4df3bf.svg);
}
This is what I see on Google Chrome developer tools when inspecting h3.encabezado
while running yarn dev
(background image is not loading):
.teaser .encabezado.verde, .teaser-secundario .encabezado.verde {
background-color: #5f9f48;
background-image: url(http://my-workstation/my-website/assets/encabezado_verde.svg);
}
system
Closed
February 3, 2022, 7:26am
14
This topic was automatically closed after 42 days. New replies are no longer allowed.