I'm maintaining a web application that uses Grunt extensively. I have to minify, copy my html, css, js files to different locations in different times. So to make it easy I created a simple javascript variable in my GruntFile.js as follows:
var path="C:/dist";
uglify: {
options: {
mangle: false
},
my_target: {
files: {
path+'/js/jsFile.js': ['src/js/jquery-1.10.2.min.js']
}
}
}
When I am building this i am getting the following error
>> SyntaxError: Unexpected token +
Can't I Use path variable in my GruntFile.js. Because I have 10 location paths.
Another way, is to utilize Grunt templates:
grunt.initConfig({
path: 'C:/dist/',
uglify: {
options: {
mangle: false
},
'<%= path %>js/jsFile.js': ['src/js/jquery-1.10.2.min.js']
}
});
The javascript object format doesn't allow a variable as the actual key:
path+'/js/jsFile.js'
This should work for you:
var path = "C:/dist";
var files = {};
files[path+"/js/jsFile.js"] = ['src/js/jquery-1.10.2.min.js'];
//...
options: {
mangle: false
},
my_target: {
files: files
}
You can see several example of using variables as the key here:
How To Set A JS object property name from a variable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With