你好,
这很可能与 #356 相关(环境变量,例如PORT
在构建时被内联)。 IISNode 通过PORT
指定要侦听的命名管道,但这不会被服务器接收,因为 Razzle 将在构建期间内联对process.env.PORT
(可能到 3000)的访问。
我们在razzle.config.js
使用此解决方法来防止内联PORT
:
module.exports = {
...
modify: (config, { target, dev }, webpack) => {
const appConfig = Object.assign({}, config);
// <strong i="13">@BUG</strong>: Do not inline certain env vars; https://github.com/jaredpalmer/razzle/issues/356
if (target === 'node') {
const idx = appConfig.plugins.findIndex(plugin => plugin.constructor.name === 'DefinePlugin');
const { definitions } = appConfig.plugins[idx];
const newDefs = Object.assign({}, definitions);
delete newDefs['process.env.PORT'];
delete newDefs['process.env.HOST'];
delete newDefs['process.env.PUBLIC_PATH'];
appConfig.plugins = [].concat(appConfig.plugins);
appConfig.plugins[idx] = new webpack.DefinePlugin(newDefs)
}
return appConfig;
},
};
你好,
这很可能与 #356 相关(环境变量,例如
PORT
在构建时被内联)。 IISNode 通过PORT
指定要侦听的命名管道,但这不会被服务器接收,因为 Razzle 将在构建期间内联对process.env.PORT
(可能到 3000)的访问。我们在
razzle.config.js
使用此解决方法来防止内联PORT
:module.exports = { ... modify: (config, { target, dev }, webpack) => { const appConfig = Object.assign({}, config); // <strong i="14">@BUG</strong>: Do not inline certain env vars; https://github.com/jaredpalmer/razzle/issues/356 if (target === 'node') { const idx = appConfig.plugins.findIndex(plugin => plugin.constructor.name === 'DefinePlugin'); const { definitions } = appConfig.plugins[idx]; const newDefs = Object.assign({}, definitions); delete newDefs['process.env.PORT']; delete newDefs['process.env.HOST']; delete newDefs['process.env.PUBLIC_PATH']; appConfig.plugins = [].concat(appConfig.plugins); appConfig.plugins[idx] = new webpack.DefinePlugin(newDefs) } return appConfig; }, };
我尝试了这个配置,但是当我在本地尝试命令 'npm run start:prod ' 时,我收到一个错误,提示没有找到 assets.json。 你能在这方面提出建议吗?
@vbutani
如果您注释掉我们从定义中删除 'process.env.PUBLIC_PATH' 的行,它会起作用吗?
@vbutani
如果您注释掉我们从定义中删除 'process.env.PUBLIC_PATH' 的行,它会起作用吗?
感谢@fabianishere的快速响应。 我的不好,在建议更改代码时,我在修改方法中发现了我的自定义代码问题。
您的代码完全可以正常工作,无需任何更改!! 您创建的自定义配置将硬编码的 PORT 值替换为捆绑的 server.js 中的 process.env.PORT。
非常感谢。 :)
最有用的评论
你好,
这很可能与 #356 相关(环境变量,例如
PORT
在构建时被内联)。 IISNode 通过PORT
指定要侦听的命名管道,但这不会被服务器接收,因为 Razzle 将在构建期间内联对process.env.PORT
(可能到 3000)的访问。我们在
razzle.config.js
使用此解决方法来防止内联PORT
: