我开发模块:
const STYLE_REGEXP = '<link rel="stylesheet" href="(.+?)">'
const STYLE_TEMPLATE = '<link rel="preload" href="$1" as="style" onload="this.onload=null;this.rel=\'stylesheet\'">' +
'<noscript><link rel="stylesheet" href="$1"></noscript>'
module.exports = async function asyncCss (options) {
this.nuxt.hook('render:route', renderRouteHandle.bind(this))
}
async function renderRouteHandle (url, result) {
result.html = result.html.replace(
new RegExp(STYLE_REGEXP, 'g'), STYLE_TEMPLATE)
}
帮了我的忙
https://github.com/nuxt/nuxt.js/issues/2822