admin管理员组文章数量:1290955
How can I configure my Next.js website (using Static Site Generation) to apply different styles based on the environment (development vs. production) at build time? I want to ensure that when the environment is set to development, dev-specific styles are applied, and for production, a different set of styles is used. What's the best approach to achieve this?
How can I configure my Next.js website (using Static Site Generation) to apply different styles based on the environment (development vs. production) at build time? I want to ensure that when the environment is set to development, dev-specific styles are applied, and for production, a different set of styles is used. What's the best approach to achieve this?
Share Improve this question asked Feb 13 at 15:17 Nick JonasNick Jonas 1151 gold badge2 silver badges13 bronze badges1 Answer
Reset to default 0In your environment variables, specify on which environment you are, (i.e: NEXT_PUBLIC_ENV) , it will be available on the client side since 'NEXT_PUBLIC' is mentionned. From there you can put your styles based on the value of your env in your theming configurations, or put it in your body's class. Here's a really simple example of how it can be implemented.
body {
&.env-dev {
.some-text {
color: 'red';
}
}
&.env-staging {
.some-text {
color: 'blue';
}
}
&.env-prod {
.some-text {
color: 'cyan';
}
}
}
<html>
<body class='env-{process.env.NEXT_PUBLIC_ENV}'>
<h1 class='some-text'>
Hello world
</h1>
</body>
</html>
本文标签:
版权声明:本文标题:next.js13 - How can I configure my Next.js website (using Static Site Generation) to apply different styles based on the environ 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741521610a2383219.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论