2createStudio / postcss-sprites

Generate sprites from stylesheets.
MIT License
413 stars 50 forks source link

How to use in gulp? #37

Closed shawx closed 8 years ago

shawx commented 8 years ago

This my configuration files,but it doesn't work... How to configure the file properly?


gulp.task('css', function () {
    var opts = {
        stylesheetPath: './dest',
        spritePath: './dest/images/'
    };
    var processors = [
        autoprefixer,
        cssnext,
        precss,
        sprites(opts)
    ];
    return gulp.src('./src/*.css')
    .pipe(sourcemaps.init())
    .pipe(postcss(processors))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./dest'));
});

thanks.

cnt1992 commented 8 years ago

HI,when I use catch an error:

TypeError: sprites is not a function

How to fixed it?

tanc commented 8 years ago

I'm also seeing a similar error when trying to use this with gulp and postcss: TypeError: object is not a function

tanc commented 8 years ago

@shawx can you re-open this ticket? Unless you have a solution in which case can you post the solution?

vvasilev- commented 8 years ago

The problem was in dropped support for module.exports in babel-plugin-transform-es2015-modules-commonjs. Now everything should work as expected.

/cc @shawx @tanc @cnt1992

vvasilev- commented 8 years ago

Use a slightly different require.

var sprites = require('postcss-sprites').default;

See Kill CommonJS default export behaviour - babel/babel#2212

shawx commented 8 years ago

@vvasilev- thx,It's helpful,My friend also found the problem.

wklc2014 commented 8 years ago

@shawx Your gulp task is working or not? I use this plugin with gulp like you and it was not work, Do you resove it?

shawx commented 8 years ago

@wklc2014 var sprites = require('postcss-sprites').default; vvasilev given the answer.