下载cross-env
"scripts": {
"start": "node scripts/start.js",
"build": "cross-env PUBLIC_URL=https://xxx.com node scripts/build.js",
"test": "node scripts/test.js"
},
再执行npm run build命令,
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="https://xxx.com/favicon.ico" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="https://xxx.com/logo192.png" />
<link rel="manifest" href="https://xxx.com/manifest.json" />
<title>React App</title>
<script defer="defer"
src="https://xxx.com/static/js/main.93d7b7b4.js"></script>
<link href="https://xxx.com/static/css/main.e6c13ad2.css"
rel="stylesheet">
</head>
<body><noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
这样文件路径前缀就不会是绝对路径了然后上传到腾讯云的对象存储COS中