Search code examples
javascriptvariableseleventy

Add a variable into a js url path


I'm trying to a add a variable into the following:

eleventyConfig.addPassthroughCopy({ "random-folder/img": "subfolder/img" });

What I've tried:

var directory = "random-folder";
eleventyConfig.addPassthroughCopy({ directory + "/img": "subfolder/img" });

However this does not work. Help hugely appreciated. The path to the left of the : is the source and to the right is destination. More information on the structure here if needed.


Solution

  • You just need to wrap property name in brackets like here:

    var directory = "random-folder";
    eleventyConfig.addPassthroughCopy({ [directory + "/img"]: "subfolder/img" });