Skip to content

Instantly share code, notes, and snippets.

@jacobrask
Created November 11, 2022 21:42
Show Gist options
  • Save jacobrask/57535220a474917eaaff9e7da38a1733 to your computer and use it in GitHub Desktop.
Save jacobrask/57535220a474917eaaff9e7da38a1733 to your computer and use it in GitHub Desktop.
Enhance in Next.js
import enhance from "@enhance/ssr";
import postProcess from "next/dist/server/post-process.js";
import MyButton from "./src/elements/my-button.mjs";
import MyIcon from "./src/elements/my-icon.mjs";
import styleTransform from "@enhance/enhance-style-transform";
const _postProcessHTML = postProcess.postProcessHTML;
postProcess.postProcessHTML = async function postProcessHTML(
pathname,
content,
...rest
) {
const html = enhance({
elements: {
"my-button": MyButton,
"my-icon": MyIcon,
},
styleTransforms: [styleTransform],
});
return _postProcessHTML(pathname, html`${content}`, ...rest);
};
export default {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment