1

I have Svelte with Webpack and it's file-loader installed

webpack.config.js's modules.esports.module.rules have:

{
    test: /\.(png|jpg|gif)$/,
    use: [
        'file-loader',
    ],
},

In App.svelte I have working code:

<script>
    import smile from './smile.jpg';
</script>

<img src={smile}>

That makes working output:

<img src="c6999a26a16dceaf99e54f8f00ecd0c5.jpg">

But

This code:

<style>
    .smile {background: url('./smile.jpg')}
</style>

<div class="smile"></div>

Outputs:

<div class="smile svelte-uv69f3"></div>

.smile.svelte-uv69f3 {
    background: url([object Module]);
}

But expected css output is:

.smile.svelte-uv69f3 {
    background: url('c6999a26a16dceaf99e54f8f00ecd0c5.jpg');
}

So, could it be fixed? Thx

MaxCore
  • 2,438
  • 4
  • 25
  • 43
  • 1
    You need to use [resolve-url-loader](https://github.com/bholloway/resolve-url-loader) for that – Orkhan Alikhanov Apr 20 '20 at 15:16
  • @OrkhanAlikhanov, Webpack's documentation did not mention it https://webpack.js.org/guides/asset-management/ (ctrl+F to background: url('./icon.png')) – MaxCore Apr 20 '20 at 15:26

0 Answers0