-
Notifications
You must be signed in to change notification settings - Fork 50
Webpack doesn't combine all images into single sprite #69
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@MwumLi Can you give more information about your setup of Webpack? |
webpack config :
|
I'm having the same issue with a pretty simple webpack config: const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const isPROD = process.env.NODE_ENV === 'production';
/**
* Plugins
*/
const plugins = [
new ExtractTextPlugin('common.css', {allChunks: true})
];
const styleLoaders = ['css-loader', 'postcss'];
const sprites = require('postcss-sprites');
/**
* Paths
*/
const SRC = path.resolve('./src');
const EXT = path.resolve('./node_modules');
const OUT = path.resolve('./dist/bundle');
module.exports = {
devtool: isPROD ? 'source-map' : 'eval',
entry: {
common: ['./src/index']
},
output: {
filename: '[name].js',
chunkFilename: 'chunk.[id].js',
path: OUT,
/* prod setting is for CSS images; js path is provided at runtime */
publicPath: isPROD ? '' : 'http://localhost:8888/static/'
},
plugins,
module: {
loaders: [{
test: /\.css$/,
loader: isPROD ? ExtractTextPlugin.extract(styleLoaders) : ['style'].concat(styleLoaders).join('!'),
include: [SRC, EXT]
}, {
test: /\.(gif|jpg|png)$/,
loader: `file-loader?name=${isPROD ? '../' : ''}assets/[hash].[ext]`
}]
},
resolve: {
modulesDirectories: [
'src',
'node_modules'
],
extensions: ['', '.js', '.json', '.jsx', '.gif', '.png', '.jpg']
},
postcss: [
sprites({
stylesheetPath: SRC,
spritePath: 'sprites',
basePath: SRC
})
]
}; The last stylesheet to get processed overwrites the sprite. Does this only work as a secondary process after the full stylesheet has been generated? |
This is the same issue as #43; Webpack processes files individually, so the sprite contains only the last file. |
same issue here. |
same to me! how to fix this? |
Hi guys, The problem is that your files are processed individually by Webpack while the plugin expects a single CSS stylesheet. I'm open for discussion if someone have an idea how this can be fixed. |
I have the same issue with vue... {
test: /\.vue$/,
loader: 'vue-loader',
options: {
postcss: [cssnext(), sprites(spritesOptions), px2rem()],
loaders: {
css: ExtractTextPlugin.extract({
loader: 'css-loader',
fallbackLoader: 'vue-style-loader'
})
}
}
} |
I have the same issue, Just in css. // a.css .box1 { background: url(./sprite/icon1.png); } .box2 { background: url(./sprite/icon2.png) } .box3 { background: url(./sprite/icon3.png) } // b.css .box1 { background: url(./sprite/icon1.png); } .box2 { background: url(./sprite/icon2.png) } Then I use gulp to get sprite img. gulp.task('dist', function (done) { var opts = { stylesheetPath: './dist', spritePath: './img', spritesmith: {padding: 4}, retina: 2, hooks: false, groupBy: function (image) { var groupName = 'x'; image.retina = true; image.ratio = 2; return Promise.resolve(groupName); } }; var stream = gulp.src('./css/*.css') .pipe(postcss([sprites(opts)])) .pipe(gulp.dest('./dist')); return stream; }); I got two new css. And They use the same sprite img. But the same sprite img only has icon1.png and icon2.png. There ditn't has icon3.png in the sprite img. |
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 #83 for some more details about my setup as well as #85. |
Does that mean postcss-sprite will not work with webpack? |
same issue ... |
same issue+1 |
1 similar comment
same issue+1 |
Has the problem been solved? |
same issue+1 |
2 similar comments
same issue+1 |
same issue+1 |
I use code to express my mean:
when I use webpack, generated a sprite :
sprite.table.png
, but onlyoffline-icon
was bundle intosprite.table.png
, the correct result should besprite.table.png
includeedit-icon.png
andoffline-icon.png
both.when use
require
and run loader once and you cann't make cache for this, so the 'wrong' result appearcan you solve the question ?
The text was updated successfully, but these errors were encountered: