introduction
为了增加环境变量到js打包中,打开next.config.js并增加env配置
module.exports = {env: {customKey: 'my-value',},}
现在你能够访问 process.env.customKey,例如
function Page() {return <h1>The value of customKey is: {process.env.customKey}</h1>}export default Page
Next.js 将在构建时使用my-value替换proces.env.customKey,尝试解构process.env变量不会工作,由于Webpack的DefinePlugin 的本质 ..
return <h1>The value of customKey is: {process.env.customKey}</h1>
这是允许的 ..
将被替换为
return <h1>The value of customKey is: {'my-value'}</h1>
