FoundationPress: want to add task to Gruntfile.js

I’m using the excellent FoundationPress and want to add a task to my watch to create a single .css file out of a single .scss file. In my case, this is for CKEditor – because it needs a separate .css file for custom formatting the input area.

However, I get this output whenever I edit my .scss file:

Read More
>> File "ckeditor/nb-ckeditor.scss" changed.
Warning: Task "sassckeditor" not found. Use --force to continue.
Aborted due to warnings.

Here’s my the content of Gruntfile.js (see ADD 1 and ADD 2 for what I added to the original content):

module.exports = function(grunt) {
  require('time-grunt')(grunt);

  grunt.initConfig(
  {
    pkg: grunt.file.readJSON('package.json'),

    sass: {
      options: {
        sourceMap: true
      },

      dist: {
        options: {
          outputStyle: 'compressed'
        },
        files: {
          'css/foundation.css': 'scss/foundation.scss'
        }
      }
    },

    /* ADD 1 BEGIN */
    sassckeditor: {
      options: {
        sourceMap: true
      },

      dist: {
        options: {
          outputStyle: 'compressed'
        },
        files: {
          'ckeditor/nb-ckeditor-fromsass.css': 'ckeditor/nb-ckeditor.scss'
        }
      }
    },
    /*  ADD 1 END */

    copy: {
      scripts: {
        expand: true,
        cwd: 'bower_components/foundation/js/vendor/',
        src: '**',
        flatten: 'true',
        dest: 'js/vendor/'
      },

      iconfonts: {
        expand: true,
        cwd: 'bower_components/fontawesome/',
        src: ['**', '!**/less/**', '!**/css/**', '!bower.json'],
        dest: 'assets/fontawesome/'
      },

    },
      'string-replace': {

        fontawesome: {
          files: {
            'assets/fontawesome/scss/_variables.scss': 'assets/fontawesome/scss/_variables.scss'
          },
          options: {
            replacements: [
              {
                pattern: '../fonts',
                replacement: '../assets/fontawesome/fonts'
              }
            ]
          }
        },
      },

    concat: {
        options: {
          separator: ';',
        },
        dist: {
          src: [

          'bower_components/foundation/js/foundation/foundation.js',
          'js/custom/*.js'

          ],
          dest: 'js/foundation.js',
        },
      },

    uglify: {
      dist: {
        files: {
          'js/foundation.js': ['js/foundation.js']
        },
        options: {
            preserveComments: false
        }
      }
    },

    watch: {
      grunt: { files: ['Gruntfile.js'] },

      sass: {
        files: 'scss/**/*.scss',
        tasks: ['sass'],
        options: {
              livereload:true,
            }
      },

      /* ADD 2 BEGIN */
      sassckeditor: {
        files: 'ckeditor/*.scss',
        tasks: ['sassckeditor'],
        options: {        
          livereload:true,    
        }
      },
      /* ADD 2 END */

      js: {
        files: 'js/custom/**/*.js',
        tasks: ['concat', 'uglify'],
        options: {
          livereload:true,
        }
      },

       all: {
        files: '**/*.php',
        options: {
            livereload:true,
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-sass');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-string-replace');

  grunt.registerTask('build', ['copy', 'string-replace:fontawesome', 'sass', 'concat', 'uglify']);
  grunt.registerTask('default', ['watch', 'sassckeditor']);
};

What am I doing wrong? Thanks in advance!

Related posts

2 comments

  1. From reading your code it looks like the error is coming from trying to run a task by the name of ‘sassckeditor’ rather than sending the .scss through the ‘sass’ task. Here’s an example of what your code should look like:

    /* ADD 2 BEGIN */
      sassckeditor: {
       files: 'ckeditor/*.scss',
       tasks: ['sass'],
       options: {        
        livereload:true,    
       }
      },
    /* ADD 2 END */
    

    This will keep your .scss file for the CKEditor separate from the rest of your Sass files, but will still run it thorough the proper ‘sass’ task that actually compiles the .scss files.

  2. Okay, got this working by simply adding an entry for “files” in my “dist” task:

    sass: {
      options: {
        sourceMap: true
      },
    
      dist: {
        options: {
          outputStyle: 'compressed'
        },
        files: {
          'css/foundation.css': 'scss/foundation.scss',
          'css/nb-ckeditor.css': 'scss/nb-ckeditor.scss' // <-- THIS
        }
      }
    },
    

Comments are closed.