2createStudio / postcss-sprites

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

spritePath with variable generates directory of the variable name. #31

Closed makotot closed 8 years ago

makotot commented 8 years ago

I want to use spritePath with variable, but postcss-sprites does not recognize variable as expected. I think '<%= path.dist %>/img/sprites.png' should be convert to ./dist/img/sprites.png.

Running "postcss:dist" (postcss) task
20 Nov 13:14:04 - [postcss-sprites] => Spritesheet <%= path.dist %>/img/sprites.png generated.
20 Nov 13:14:04 - [postcss-sprites] => Done.
>> 1 processed stylesheet created.

Done, without errors.

Below is my Grunfile.

module.exports = function (grunt) {

  require('time-grunt')(grunt);
  require('jit-grunt')(grunt);

  grunt.initConfig({

    path: {
      src: './src',
      dist: './dist'
    },

    clean: {
      all: ['<%= path.dist %>']
    },

    copy: {
      all: {
        files: [
          {
            expand: true,
            cwd: '<%= path.src %>/img/',
            src: '**/*.*',
            dest: '<%= path.dist %>/img/'
          }
        ]
      }
    },

    sass: {
      all: {
        files: [
          {
            expand: true,
            cwd: '<%= path.src %>/scss',
            src: '*.scss',
            dest: '<%= path.dist %>/css',
            ext: '.css'
          }
        ]
      }
    },

    postcss: {
      options: {
        sourcemap: true,
        processors: [
          require('postcss-sprites')({
            stylesheetPath: '<%= path.dist %>/css',
            spritePath: '<%= path.dist %>/img/sprites.png'
          })
        ]
      },
      dist: {
        src: '<%= path.dist %>/css/index.css'
      }
    }
  });

  grunt.registerTask('default', ['clean']);
  grunt.registerTask('build', ['clean', 'copy', 'sass', 'postcss']);
};
vvasilev- commented 8 years ago

This is not an issue of the plugin itself, just Grunt doesn't replace template strings inside function call, you can see it here. I can recommend you to strip the template strings from the plugin configuration to workaround this problem. :)

makotot commented 8 years ago

I see. Thanks :)