https://[staging host].com/images/the-image.jpg instead of https://[staging host].com/wp-content/themes/the-theme-dir/images/the-image.jpg
I have setPublicPath set in bud.config.js:
/**
* @typedef {import('@roots/bud').Bud} bud
*
* @param {bud} app
*/
module.exports = async (app) => {
app
/**
* Application entrypoints
*
* Paths are relative to your resources directory
*/
.entry({
app: ['@scripts/app', '@styles/app'],
editor: ['@scripts/editor', '@styles/editor'],
})
/**
* These files should be processed as part of the build
* even if they are not explicitly imported in application assets.
*/
.assets('images')
/**
* These files will trigger a full page reload
* when modified.
*/
.watch('resources/views/**/*', 'app/**/*')
/**
* Target URL to be proxied by the dev server.
*
* This should be the URL you use to visit your local development server.
*/
.proxy('http://example.test')
/**
* Development URL to be used in the browser.
*/
.serve('http://0.0.0.0:3000')
/**
* Relative path to the public directory.
*/
.setPublicPath('/wp-content/themes/the-theme-dir/public/');
};
How do I get the compiler to add â/wp-content/themes/the-theme-dir/â?
In the stylesheet(s) you either use stylesheet-relative paths (e.g. url('../../../images/test.png')) (paths are always relative to entrypoint stylesheet, even if imported in SASS by the way), or absolute paths, but then the asset URLs need to be resolved by bud (underlying webpack).
It appears that development for this feature is in progress, but I am not sure whether it is possible yet:
Using stylesheet-relative URLs works nice for me though and doesnât introduce an extra layer of complexity (resolving asset URLs/modifying URLs), the only exception is when I want to modify inlined SVGs (where CSS limitations force me to do this) and then I use a PostCSS plugin, which would resolve URLs differently anyway.
setPublicPath() doesnât seem to do anything. Background images in CSS are compiled to host.com/images/the-image.jpg instead of host.com/wp-content/themes/theme-name/public/images/the-image.jpg regardless of what I put there.
Iâm using Sass instead of Tailwind.
For example, the following CSS in source file resources/styles/common/_global.scss (imported to resources/styles/app.scss):
background-image: url(../images/text-accent.svg);
(Note ../)
Gives an error:
webpack built bud e7479ea4e005f3e68ef5 in 4268ms
â Ś 98% emitting
ERROR ./resources/styles/app.scss
Module not found: Error: Canât resolve â./images/text-accent.svgâ in â./resources/stylesâ
ERROR ./resources/styles/app.scss
Module not found: Error: Canât resolve â./images/background-accent.svgâ in â./resources/stylesâ
@avior Iâm having the exact same problem when running yarn dev (described here). Have you found a solution for it? If so could you share what resolves this issue?
Iâve unlisted and locked this topic because itâs one of three old topics youâve bumped all related to the same thing. In the future, do not bump several topics for the same issue.