簡體   English   中英

如何在 amp 模式下配置 next.js 以支持 css 文件?

[英]How to config next.js to support css file in amp mode?

默認情況下 next.js 創建一個外部文件並將 css 推送到它。 但是 amp 僅支持內聯樣式。 如何配置 next.js 以在 amp 模式下支持 css (tailwindcss)。 現在 next.js 默認只支持 amp 模式下的styled jsx樣式。 我之前在spectrum.chat 社區中問過這個問題,但沒有得到任何答案。

我試圖在 amp 頁面上編寫內聯 CSS,但我沒有在控制台上看到我的 CSS 代碼。 之后,我找到了解決方案。 我正在共享代碼。 我希望如此,它有助於解決您的錯誤。

const initialProperty = {
'amp-custom': '',
};

render() {
const styleElement = (
<style jsx {...initialProperty}>
{
`.example-button { color: black; }`
}
</style>
);
}
return (

<React.Fragment>
 {styleElement}
</React.Fragment>
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM