首页 > 解决方案 > React Create App 未在 npm run build 上创建 Bundle.js

问题描述

我有一个通过 React Create App 构建的项目,我正在按照本教程将其部署到 GitHub Pages。部署本身几乎可以工作,因为我<script>在 index.html 上方写的任何内容都已部署到正确的 URL,但我不知道应该加载什么。在本教程中,它们链接build/bundle.js,但是当我运行时npm run build,没有创建任何捆绑文件。我认为我只需要链接到我的捆绑应用程序就可以解决我的问题,但我不知道在哪里可以找到它。我还没有从开箱即用的 react-create-app 重新配置 babel 或 webpack。我的 index.HTML:

<html>
  <head>
    <meta charset="utf-8">
    <!-- Start Single Page Apps for GitHub Pages -->
    <script type="text/javascript">
      // Single Page Apps for GitHub Pages
      // MIT License
      // https://github.com/rafgraph/spa-github-pages
      // This script checks to see if a redirect is present in the query string,
      // converts it back into the correct url and adds it to the
      // browser's history using window.history.replaceState(...),
      // which won't cause the browser to attempt to load the new url.
      // When the single page app is loaded further down in this file,
      // the correct url will be waiting in the browser's history for
      // the single page app to route accordingly.
      (function(l) {
        if (l.search[1] === '/' ) {
          var decoded = l.search.slice(1).split('&').map(function(s) { 
            return s.replace(/~and~/g, '&')
          }).join('?');
          window.history.replaceState(null, null,
              l.pathname.slice(0, -1) + decoded + l.hash
          );
        }
      }(window.location))
    </script>
    <!-- End Single Page Apps for GitHub Pages -->

  </head>
  <body>
    <div id="root"></div>
    <!-- single page app in bundle.js -->
    <p>Testing</p>
    <script src="/build/bundle.js"></script>
  </body>
</html>

标签: javascriptwebpackbundlegithub-pagesreact-create-app

解决方案


推荐阅读