【问题标题】:Webpack Build generates index.html but blank when loaded in browserWebpack Build 生成 index.html 但在浏览器中加载时为空白
【发布时间】:2021-01-18 16:23:23
【问题描述】:

请找到我的repo@https://github.com/reachlinlen/empexplorerWebpack 配置是https://github.com/reachlinlen/empexplorer/blob/master/webpack.config.js

为什么 index.html 在 npm run build 后没有渲染页面? Tailwind css 是否会导致任何问题?

【问题讨论】:

    标签: javascript reactjs webpack


    【解决方案1】:

    您的构建一切都很好(但不要忘记在依赖项中添加“axios”)。如果您希望您的应用程序使用静态文件服务器(如 www.test.com/path/index.html),则需要使用 HashRouter 而不是 BrowserRouter。

    https://github.com/ReactTraining/react-router/blob/master/FAQ.md#why-doesnt-my-application-render-after-refreshing

    【讨论】:

    • 完美运行。非常感谢。但是 github.com/lewislbr/gauzy-react-app 在这个 repo 中,使用了 BrowserRoute 但仍然呈现。怎么样?
    • 它只呈现标题而不呈现路由器内容。 BrowserRouter 不适用于本地文件协议 (file://path/index.html)。这是正常行为,因此您无需将路由器更改为 HashRouter(我们使用它来检查捆绑包是否一切正常)。您将从服务器获取所有静态内容,BrowserRouter 将正常工作。
    【解决方案2】:

    我找到了另一种方式来提供 webpack 5 构建版本。

    在终端

    npm i -g http-server
    
    cd dist && http-server
    

    现在你的构建版本应该是http://127.0.0.1:8080

    我希望这可以帮助仍然被这个问题困扰的人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多