【发布时间】:2019-12-06 12:26:35
【问题描述】:
我有一个使用命令 npx create-react-app my-app 创建的 reactjs 应用程序,我使用 yarn build 构建我的项目
json 包:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
一旦我构建了应用程序 index.html 如下所示(它具有所有静态文件的绝对路径),
<script type="text/javascript" src="/static/js/main.af2bdfd5.js"></script>
<link href="/static/css/main.097da2df.css" rel="stylesheet">
<link rel="shortcut icon" href="/favicon.ico">
我希望这些来源如下所示(需要提供公共 URL)
<script type="text/javascript" src="http://localhost:3000/static/js/main.af2bdfd5.js"></script>
<link href="http://localhost:3000/static/css/main.097da2df.css" rel="stylesheet">
<link rel="shortcut icon" href="http://localhost:3000/favicon.ico">
我尝试将 PUBLIC_URL 和 homepage 添加到 package.json 中,但没有成功。
【问题讨论】:
标签: javascript reactjs npm deployment build