rsnext/packages/next/next-server/server/optimize-amp.ts
JJ Kasper 5febe218a6
Add nccing AMP optimizer (#21980)
This adds ncc'ing the AMP optimizer package to speed up install times and cache the runtime. 

Closes: https://github.com/vercel/next.js/issues/20404
2021-02-11 09:55:56 +00:00

13 lines
330 B
TypeScript

export default async function optimize(
html: string,
config: any
): Promise<string> {
let AmpOptimizer
try {
AmpOptimizer = require('next/dist/compiled/@ampproject/toolbox-optimizer')
} catch (_) {
return html
}
const optimizer = AmpOptimizer.create(config)
return optimizer.transformHtml(html, config)
}