I'm trying to create multi-language webpage.
I need to copy /assets into every language folder:
eleventy.js
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy({ assets: "en" });
eleventyConfig.addPassthroughCopy({ assets: "fr" });
};
Project structure:
_includes
assets
en
fr
But /assets copied only into /fr language.
Any ideas?
Interesting. It looks like addPassthroughCopy() is proxying an internal passthroughCopies property which is a simple object, so I'm guessing that using the same key ("assets") is just overwriting the existing value in the passthroughCopies object.
I wonder if you'd have to copy the assets yourself using a 3rd party lib like copy, or cp, or fs-extra.
https://github.com/11ty/eleventy/blob/0d18f4d1ca4c0587c1ebba298a9603ca11429243/src/UserConfig.js#L299-L316
https://github.com/11ty/eleventy/blob/0d18f4d1ca4c0587c1ebba298a9603ca11429243/src/UserConfig.js#L44
Not the prettiest solution, but I liked fs-extra's API the best:
const path = require("path");
const fs = require("fs-extra");
module.exports = eleventyConfig => {
/*
// The src/assets files are only copied to the "de/" (last) folder.
eleventyConfig.addPassthroughCopy({ "src/assets": "en" });
eleventyConfig.addPassthroughCopy({ "src/assets": "fr" });
eleventyConfig.addPassthroughCopy({ "src/assets": "de" });
*/
const dir = {
input: "src",
output: "www"
};
const locales = ["en", "fr", "de"];
for (const locale of locales) {
try {
fs.copySync(
// src: "./src/assets/"
path.join(dir.input, "assets"),
// dest: "./www/{{ locale }}/"
path.join(dir.output, locale)
);
} catch (err) {
console.error(err.message);
process.exitCode = 1;
}
}
return {
dir
};
};
$ tree src
src/
βββ _data/
βββ _includes/
βββ assets/
βΒ Β βββ site.css
βΒ Β βββ site.js
βββ index.njk
3 directories, 3 files
$ tree www
www/
βββ de/
βΒ Β βββ site.css
βΒ Β βββ site.js
βββ en/
βΒ Β βββ site.css
βΒ Β βββ site.js
βββ fr/
βΒ Β βββ site.css
βΒ Β βββ site.js
βββ index.html
3 directories, 7 files
Iβd imagine that syntax would probably be something like:
eleventyConfig.addPassthroughCopy({ "src/assets": ["en", "de", "fr"] });
This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.
View the enhancement backlog here. Donβt forget to upvote the top comment with π!
eleventyConfig.addPassthroughCopy({ "src/assets": ["en", "de", "fr"] });
This seems to fail with the following message:
> Having trouble copying
`TemplateWriterWriteError` was thrown
> Having trouble copying './src/assets'
`TemplatePassthroughManagerCopyError` was thrown
> The "path" argument must be of type string. Received type object
`TypeError` was thrown:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
Most helpful comment
Iβd imagine that syntax would probably be something like: