only minify compiled MDX source in production

This commit is contained in:
2022-02-03 10:54:24 -05:00
parent 3dcf6cf45f
commit 0127004e3a
5 changed files with 84 additions and 78 deletions
+17 -12
View File
@@ -73,21 +73,26 @@ export const getNote = async (slug: string): Promise<NoteType> => {
},
});
// next-mdx-remote v4 doesn't (yet?) minify compiled JSX output, see:
// https://github.com/hashicorp/next-mdx-remote/pull/211#issuecomment-1013658514
// ...so for now do it manually (and conservatively) with terser when building for production.
const compiledSource =
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
? (
await minify(source.compiledSource, {
ecma: 2018,
module: true,
parse: { bare_returns: true },
compress: { defaults: true },
sourceMap: false,
})
).code
: source.compiledSource;
return {
frontMatter,
source: {
// next-mdx-remote v4 doesn't (yet?) minify compiled JSX output, see:
// https://github.com/hashicorp/next-mdx-remote/pull/211#issuecomment-1013658514
// ...so do it manually (and conservatively) with terser for now.
compiledSource: (
await minify(source.compiledSource, {
ecma: 2018,
module: true,
parse: { bare_returns: true },
compress: { defaults: true },
sourceMap: false,
})
).code,
compiledSource,
},
};
};
+1 -1
View File
@@ -15,7 +15,7 @@ import meJpg from "../public/static/images/me.jpg";
export const defaultSeo: DefaultSeoProps = {
defaultTitle: `${config.siteName} ${config.shortDescription}`,
titleTemplate: `%s ${config.siteName}`, // appends ` siteName` to title provided by each page
titleTemplate: `%s ${config.siteName}`, // appends ` siteName` to title provided by each page (except home)
description: config.longDescription,
openGraph: {
site_name: config.siteName,