New Oct 28, 2025

Copy *and* Paste? …in this Economy?

Top Front-end Bloggers All from Zach Leatherman View Copy *and* Paste? …in this Economy? on zachleat.com

Astute visitors to the Eleventy Documentation will notice something new on the code blocks on the site.

A wild copy-to-clipboard component has appeared:

This feature been a long time coming and is our first use of Web Awesome on the docs (via the <wa-copy-button> custom element). Take special note of the unparalleled synergy of the Font Awesome icon used by the Web Awesome component used on the Eleventy docs.

Usage

Direct from CDN

There are a few ways to use the Copy Button component stock, with the easiest being to load the script directly from the CDN, like so (via jsdelivr):

<script type="module" src="https://cdn.jsdelivr.net/npm/@awesome.me/webawesome@3.0.0/dist-cdn/components/copy-button/copy-button.js"></script>

Or via unpkg:

<script type="module" src="https://unpkg.com/@awesome.me/webawesome@3.0.0/dist-cdn/components/copy-button/copy-button.js"></script>

Bundling

For this implementation we used esbuild to create a focused bundle for the single Web Awesome component (though this esbuild code would work for any JavaScript file).

We went with this method for improved runtime performance and to reduce the number of third-party dependencies on the web site (with a nod to André Jaenisch). You can do the same with the following bit of Eleventy configuration (e.g. in a eleventy.config.js file):

// eleventy.config.js
// don’t forget to `npm install esbuild -D`
import esbuild from "esbuild";
import { fileURLToPath } from "node:url";

async function esbuildToFile(entryPoints, outfile, options = {}) { return esbuild.build(Object.assign({ entryPoints, platform: "browser", format: "esm", bundle: true, minify: true, banner: { js: </span><span class="token string">/* via </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>entryPoints<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> */</span><span class="token template-punctuation string">, }, outfile, }, options)); }

async function bundleModuleToFile(modulePath, outfile) { let sourcefile = fileURLToPath(import.meta.resolve(modulePath)); return esbuildToFile([ sourcefile ], outfile); }

export default async function(eleventyConfig) { let outfile = path.join(eleventyConfig.directories.output, "js/copy-button.js");

// This will run once per build/serve/watch // (not with subsequent builds, save for config file changes) await bundleModuleToFile("@awesome.me/webawesome/dist/components/copy-button/copy-button.js", outfile); }

Markdown Code Block Wrappers

This task also served as the impetus for fixes related to wrapper elements around code blocks in Markdown, documented in a previous blog post on this very web site.

Scroll to top