【问题标题】:Run React dev server inside another application在另一个应用程序中运行 React 开发服务器
【发布时间】:2020-08-25 01:51:16
【问题描述】:

在我们旧的 .jsp 应用程序中,我们正在集成 react。

我的 react 开发服务器在 http://localhost:3000 上运行,现有应用程序在 http://localhost:8100 上运行。

我将反应所需的所有 js 和 CSS 文件包含在 JSP 页面中。这工作正常。

当我在 React 中使用延迟加载时,例如:

import('some-file.js').then(file => {
   // Some work
});

在这种情况下,Webpack 尝试从 localhost:8100 而不是开发服务器加载块。

我正在使用 react-script 进行开发和构建。

【问题讨论】:

  • 可以尝试在 webpack.config.js 文件中添加 module.exports { output:{publicPath: ' "localhost:3000/static/js/dist or http://0.0.0.0:3000/dist"'} } 并检查是否行不行???
  • 上面评论中的 http:/locallhost:3000/dist
  • 上面的东西有用吗??
  • 感谢 SAI 的快速回复。让我验证一下。
  • 感谢 PALLAMOLLA SAI,您的想法可行。我通过设置 publicPath: "http:localhost:3000" 来修复它。

标签: reactjs webpack react-router webpack-dev-server


【解决方案1】:

尝试在 webconfig.js 文件中添加 publicPath,如下所示。

output: {
        //
        publicPath: 'http://localhost:3000/static/js/dist' or
        // publicPath : 'http://localhost:3000/dist'
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 2020-03-03
    • 2020-11-17
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    相关资源
    最近更新 更多