2016-05-30 7 views
0
grunt.config('sass', { 
    options: { 
     sourceMap: true 
    }, 
    dist: { 
     options: { 
     outputStyle: 'compact' 
     }, 
     files: { 
     '/css/site.css': 'main/scss/site.scss', 
     '/css/template.home.css': 'main/scss/templates/home.scss' 
     '/css/template.contact.css': 'main/scss/templates/contact.scss' 
     '/css/template.something.css': 'main/scss/templates/something.scss' 
     } 
    } 
}); 

ist es eine Möglichkeit ist, diesen Teil gut zu handhaben (Nachdenken über ein Muster, aber ich über die Möglichkeit, nicht sicher)Grunt j mit regulären Ausdrücken

'/css/template.home.css': 'main/scss/templates/home.scss' 
'/css/template.contact.css': 'main/scss/templates/contact.scss' 
'/css/template.something.css': 'main/scss/templates/something.scss' 
+0

"diesen Teil handhaben"? – ClasG

+0

Ja @ClasG Ich möchte diese drei Zeilen auf eins reduzieren, da ich noch einige andere Zeilen hinzufügen muss. Danke – Dhanan

Antwort

2

Wenn Sie die Konfiguration als JS erklären Objekt könnte man es wie folgt tun:

var cfg = { 
 
     options: { 
 
      sourceMap: true 
 
     }, 
 
     dist: { 
 
      options: { 
 
       outputStyle: 'compact' 
 
      }, 
 
      files: { 
 
       '/css/site.css': 'main/scss/site.scss', 
 
       '/css/template.home.css': 'main/scss/templates/home.scss', 
 
       '/css/template.contact.css': 'main/scss/templates/contact.scss', 
 
       '/css/template.something.css': 'main/scss/templates/something.scss' 
 
      } 
 
     } 
 
    }, 
 
    grunt = { 
 
     config: function() { 
 
     document.write('<br/><strong>grunt config set</string><br/>'); 
 
     } 
 
    }; 
 

 
    document.write('<br/>"files" before new config:<br/><br/>'); 
 

 
    for (var property in cfg.dist.files) { 
 
     if (cfg.dist.files.hasOwnProperty(property)) { 
 
      document.write(property + ' = ' + cfg.dist.files[property] + '<br/>'); 
 
     } 
 
    } 
 

 
    document.write('<br/>"files" after added config:<br/><br/>'); 
 

 
    cfg.dist.files['/css/what ever...'] = 'the/latest/path'; 
 

 
    for (var property in cfg.dist.files) { 
 
     if (cfg.dist.files.hasOwnProperty(property)) { 
 
      document.write(property + ' = ' + cfg.dist.files[property] + '<br/>'); 
 
     } 
 
    } 
 

 
    grunt.config('sass', cfg);

Beachten Sie die

cfg.dist.files['/css/what ever...'] = 'the/latest/path'; 

Das ist, wo die zusätzliche Konfiguration hinzugefügt wird.

+0

Sehr geschätzt! Ich möchte keine Dateinamen in wo wo definieren. Ich muss alle Dateien einschließen, die diesem Muster folgen, um meine Konfiguration einzuschließen. So etwas wie dieses '/css/template.%1.css ':' main/scss/templates/$ 1.scss '' – Dhanan