diff --git a/_includes/head.liquid b/_includes/head.liquid index 3dc66394a..04558622c 100644 --- a/_includes/head.liquid +++ b/_includes/head.liquid @@ -36,7 +36,7 @@ {%- endif -%} { + await writeFile(file, shrinkSvg(await readFile(file, 'utf8'))); + }, + // `.min` in a name is a claim about what is inside it, so only the + // build that minifies makes one, and head.liquid asks for whichever + // matches. The stylesheet is named the same way. + '.js': async (file) => { + await writeFile( + file.replace(/\.js$/, '.min.js'), + await shrinkJs(await readFile(file, 'utf8')) + ); + await unlink(file); + }, }; // Assets are copied rather than rendered, so no transform reaches them. @@ -258,11 +269,11 @@ export default async function (eleventyConfig) { entries.map(async (entry) => { const squeeze = squeezers[extname(entry.name)]; + // A name that already says `.min` was minified by whoever wrote it. if (!entry.isFile() || squeeze === undefined) return; + if (entry.name.endsWith('.min.js')) return; - const file = join(entry.parentPath, entry.name); - - await writeFile(file, await squeeze(await readFile(file, 'utf8'))); + await squeeze(join(entry.parentPath, entry.name)); }) ); });