2017-01-19 5 views
0

Mit contrib-sass und contrib-watching will ich nur benötigte Dateien kompilieren weil ich eine Menge scss-Datei auf dem Produktionsserver habe.Kompilieren nur benötigt sass file whit grunt

Ich schreibe diese Gruntfile, aber etwas funktioniert nicht. Zusehen klappt, aber kompiliert nichts.

module.exports = function(grunt) { 

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

    watch: { 
    sass: { 
     files: [ 
      'sites/**/scss/*.scss' 
     ], 
     tasks: ['sass'], 
     options: { 
      spawn: false 
     } 
    } 
    }, 

    sass: { 
    dist:{ 
     options: { 
      style: 'compressed' 
     }, 
     files: objDestSource 
    } 
    } 

}); 

// On watch events configure jshint:all to only run on changed file 
grunt.event.on('watch', function(action, filepath) { 
    var filepath_scss = filepath; 
    var filepath_css = filepath.replace("scss", "css"); 
    filepath_css = filepath_css.replace("scss", "css"); 
    filepath= '\''+filepath_css+'\' : \''+filepath_scss+'\''; 
    console.log(filepath); 
    grunt.config('sass.dist.files', filepath); 
}); 

grunt.loadNpmTasks('grunt-contrib-sass'); 
grunt.loadNpmTasks('grunt-contrib-watch'); 
grunt.registerTask('default',['watch']); 

};

Antwort

0

Ich löste es. Thi ist mein Script-Code:

module.exports = function (Grunzen) {

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

    watch: { 
    sass: { 
     files: [ 
      'pippo/*/scss/*.scss', 
      'pippo/test/*/scss/*.scss' 
     ], 
     tasks: ['sass'], 
     options: { 
      spawn: false 
     } 
    } 
    }, 

    sass: { 
    dist:{ 
     options: { 
      style: 'compressed' 
     }, 
     files: { 
     'pippo/test/statics/css/ie.css' : 'pippo/test/statics/scss/ie.scss' 
     } 
    } 
    } 

}); 

grunt.event.on('watch', function(action, filepath) { 
    var filepath_scss = filepath; 
    var filepath_css = filepath.replace("scss", "css"); 
    filepath_css = filepath_css.replace("scss", "css"); 
    var finalpath = {}; 
    finalpath[filepath_css] = filepath_scss; 
    grunt.config('sass.dist.files', finalpath); 
}); 

grunt.loadNpmTasks('grunt-contrib-sass'); 
grunt.loadNpmTasks('grunt-contrib-watch'); 
grunt.registerTask('default',['watch']); 

};