【问题标题】:create-react-app: Change src of bundle.js in developmentcreate-react-app:在开发中更改 bundle.js 的 src
【发布时间】:2017-10-18 10:49:08
【问题描述】:

我正在尝试使用 create-react-app 更改开发中 bundle.js 的 src。

默认路径为:/static/js/bundle.js

<body>
<div id="root"></div>
</script><script type="text/javascript" src="/static/js/bundle.js"></script></body>

在我们的生产中,我们使用 Apache 作为 API 的代理,以测试 SSO 和其他功能。所以我必须在路径中添加一些字符串,就像这样:myApp/static/js/bundle.js

<body>
<div id="root"></div>
</script><script type="text/javascript" src="myApp/static/js/bundle.js"></script></body>

我在 package.json 中尝试了主页,但它只适用于 npm run build。 它也不是代理设置,也不是 .env 中的主机

这甚至可以通过 create-react-app 实现吗?我检查了文档,但没有找到任何解决方案。

【问题讨论】:

    标签: create-react-app


    【解决方案1】:

    您将不得不“npm runeject”并修改 webpack 文件以更改输出。

    【讨论】:

      【解决方案2】:

      有点晚了,但如果这对其他人有帮助,这就是你实现它的方式。弹出后查看config文件夹,文件:webpack.config.dev.js:

      const publicPath = '/';
      // `publicUrl` is just like `publicPath`, but we will provide it to our app
      // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
      // Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
      const publicUrl = '';
      

      您可以在此处更改此值,或者,第二个选项是创建一个 .env 文件并添加:

      PUBLIC_URL=/xxx
      

      【讨论】:

        猜你喜欢
        • 2019-06-24
        • 1970-01-01
        • 2018-11-16
        • 2021-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-17
        • 2019-06-01
        相关资源
        最近更新 更多