0

I'm trying to add a custom task in a salsjs application.

This is what I've done so far:

  • Added a new file in the task/config directory named cssminTemplates.js
  • Modify the default.js file in the task/registerd directory.

My cssminTemplates.js is basically a copy of the cssmin.js standard file:

module.exports = function(grunt) {

 grunt.config.set('cssminTemplates', {
    dist: {
        src: ['asset/templates/above_the_fold.css'],
        dest: 'asset/templates/above_the_fold.min.css'
    }
 });
grunt.loadNpmTasks('grunt-contrib-cssmin');
};

default.js file as been modified as follow:

module.exports = function (grunt) {
 grunt.registerTask('default', [
  'compileAssets',
  'linkAssets',
  'cssminTemplates',
  'watch']);
};

But when I start the app with sails lift command I got this error:

Warning: Task "cssminTemplates" not found. 

I try to change the 'cssminTemplates' with 'cssmin' and I've got no errors.

Ilproff_77
  • 207
  • 1
  • 3
  • 17

1 Answers1

0

In Grunt.js (ref), cssminTemplates function is invoked instead of cssmin which is loaded via grunt.loadNpmTasks('grunt-contrib-cssmin');. This is where the function is invoked:

function invokeConfigFn(tasks) {
    for (var taskName in tasks) {
        if (tasks.hasOwnProperty(taskName)) {
            // Invoking the function....
            tasks[taskName](grunt);
        }
    }
}

In other words, you are setting the function (cssminTemplates) and invoking it from Grunt.js but Grunt loaded cssmin instead via loadNpmTasks(). I think that's why setting cssminTemplates does not work.

novasaint
  • 700
  • 8
  • 13