`assets/` now needed for asset paths?

After updating a Sage 10 to latest commit (beta2 + Remove config and bootstrap directories (#2839)),
the URIs obtained by using Roots\asset(...) were not loading anymore.
It turned out that the URIs need to have assets/ prepended. Otherwise the public URI that the Roots\asset(...) function would return would be verbatim the relative input URL (e.g. images/login-logo.svg results in the same images/login-logo.svg), as the asset can’t be found in the build manifest and the fallback is just the input URI.

In the public/ build directory however the build artifacts will end up in assets/ sub-directory.

Usage example that would be affected:


namespace App;

use function Roots\asset;

 * Login page
function login_logo()
{ ?>
    <style type="text/css">
        #login h1 a,
        .login h1 a {
            background-image: url(<?php echo asset('assets/images/login-logo.svg')->uri(); ?>);
            background-size: contain;
            background-position: center;
<?php }
add_action('login_enqueue_scripts', __NAMESPACE__ . '\\login_logo');

assets/images/login-logo.svg must be used now instead of just images/login-logo.svg to make the public URI fit the actual directory structure of the builds.

So is prepending assets/ to all URIs passed to the asset-related functions the right approach or is this something that needs to be fixed in Sage so URIs without assets/ will be found in the manifest/public build directory?

What about emitting a warning when trying to obtain a public URI for an URI that can’t be found in the build manifest?

1 Like

@ben: Ah, totally missed that issue although I first tried to find an existing one.

This topic was automatically closed after 42 days. New replies are no longer allowed.