1

通过 Nx Nextjs 原理图创建的 Nextjs 应用程序为在生产构建运行时在 getInitialProps 中访问的 publicRuntimeConfig 提供未定义但在开发模式下它可以完美运行

next.config.js

module.exports = { serverRuntimeConfig: { // Will only be available on the server side mySecret: 'secret', secondSecret: process.env.SECOND_SECRET // Pass through env variables }, publicRuntimeConfig: { // Will be available on both server and client staticFolder: '/static' } };

获取初始道具

import getConfig from 'next/config'; const { publicRuntimeConfig } = getConfig(); ... Index.getInitialProps = async ctx => { console.log('I am here'); console.log(publicRuntimeConfig.staticFolder); // Undefined when running prod build return {}; };

原始 Github 问题在这里

4

0 回答 0