dev-null dev-null - 15 days ago 5
Javascript Question

Dynamically generate map key in Grunt plugin config

I use this code in grunt config:

const libDir = 'public/lib'
const cssDir = 'public/css'

// Project configuration.
grunt.initConfig({

watch: {
scripts: {
files: '**/*.js',
tasks: ['default'],
},
},

clean: [libDir],

bower_concat: {
all: {
dest: {
'js': libDir + '/vendor.js',
'css': libDir + '/vendor.css'
},
}
},

sass: {
options: {
sourceMap: true
},
dist: {
files: {
'output.css': 'input.scss'
}
}
}
});


How do I generate
output.css
dynamically by concatenating
cssDir
and some string ?

I tried using templating but it ignores
cssDir
.

Answer

I found out that ES6 supports dynamic property keys so basically this solves the problem as I can now compute both the key and value as dirVar + 'outputFile': inputDir + 'input.file'

Comments