Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how to configure load of images and fonts relatively to the CSS file? #741

Open
romainneutron opened this issue Apr 28, 2020 · 1 comment

Comments

@romainneutron
Copy link

Hello,

First, I'd like to give you a big 馃憦 for this work.
We just finished to port our manual webpack wiring in our Symfony app to webpack encore, and it works well !

However, I had to use configureLoaderRule in order to load images and fonts from a relative path:
We deploy our assets on a CDN, in a subfolder. When we're building assets, we dont know yet what will be the subfolder.

So we want that images and fonts are loaded relatively to the css file instead of an absolute path:

Encore
    // directory where compiled assets will be stored
    .setOutputPath('../public/build')
    // public path used by the web server to access the output path
    .setPublicPath('/build')

    // only needed for CDN's or sub-directory deploy
    .setManifestKeyPrefix('build/')

    // Needed because webpack encore use absolute path, and we release in a CDN folder
    .configureLoaderRule('fonts', (rules) => {
        rules.options.publicPath = function (url) {
            return `./${url}`;
        };
    })

    // Needed because webpack encore use absolute path, and we release in a CDN folder
    .configureLoaderRule('images', (rules) => {
        rules.options.publicPath = function (url) {
            return `./${url}`;
        };
    })

module.exports = Encore.getWebpackConfig();

When using configureLoaderRule a WARNING is displayed when building, and I was wondering if there were a better way to achieve this.
I've seen that there were some works years ago at #179, but maybe there is a more recent and proper way of doing this that I've missed.

Thanks!

@LeoShivas
Copy link

Hello,

I also need relative paths for fonts. Any news ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants