question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack doesn't combine all images into single sprite

See original GitHub issue

I use code to express my mean:

// aa.css
.a {
  background: url(./img/sprites/default/table/edit-icon.png)
}

// bb.css
.b {
  background: url(./img/sprites/default/table/offline-icon.png)
}
// main.js
require('aa.css');
require('bb.css'))

when I use webpack, generated a sprite : sprite.table.png, but only offline-icon was bundle into sprite.table.png, the correct result should be sprite.table.png include edit-icon.png and offline-icon.png both. when use require and run loader once and you cann’t make cache for this, so the ‘wrong’ result appear

can you solve the question ?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jednanocommented, Feb 24, 2017

I use the following webpack CSS rule:

exports.css = {
    test: /\.css$/,
    use: [
        'style-loader',
        'css-loader',
        {
            loader: 'postcss-loader',
            options: { plugins: postcssInit }
        }
    ]
};

function postcssInit() {
    const sheetName = basename(this.resourcePath, '.css');
    return loadPlugins.call(this, { sheetName });
}

function loadPlugins({ sheetName }) {
    return [
        // some plugins...
        require('postcss-sprites')({
            groupBy: () => Promise.resolve(sheetName),
            // more opts...
        }),
        // more plugins...
    ];
}

See https://github.com/2createStudio/postcss-sprites/issues/83 for some more details about my setup as well as https://github.com/2createStudio/postcss-sprites/pull/85.

0reactions
Chorercommented, Aug 18, 2021

same issue+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to load images and spritesheets with Phaser 3 and ...
I have a Vue app with Webpack and Phaser 3 and I am trying to load images and spritesheets in my main scene....
Read more >
Loading Images - SurviveJS
It's possible to generate sprite sheets out of smaller images to combine them into a single request. Webpack allows you to load images...
Read more >
Make fewer HTTP requests: What this means and how to do it
CSS sprites is a technique to combine several images into a single image called a sprite sheet. Rather than downloading each image separately, ......
Read more >
postcss-loader | webpack - JS.ORG
Allows to set options using config files. Options specified in the config file are combined with options passed to the loader, the loader...
Read more >
Working with Images in Stylesheets with PostCSS - CSS-Tricks
We all work with images in our CSS. ... which accomplishes one of the major advantages of image sprites: combining HTTP requests. With...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found