我在hbuilderx中用uni-app默认模板创建了一个项目,开发运行在企业微信环境中的h5站点。为了便于调试微信jssdk相关功能,我需要在本地调试时使用带域名的地址来访问,现发现问题如下:
直接通过hbuilderx运行是生成的首页index.html如下:
<!DOCTYPE html>
<html lang=zh-CN>
<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<title>生产运营2.0</title>
<script>
var coverSupport = 'CSS'in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')
</script>
<link rel=stylesheet href=/static/index.2da1efab.css>
</head>
<body>
<noscript>
<strong>Please enable JavaScript to continue.</strong>
</noscript>
<div id=app></div>
<script src=/static/js/chunk-vendors.bd1ef1be.js></script>
<script src=/static/js/index.78d3480f.js></script>
</body>
</html>
打包发布后的首页index.html如下:
<!DOCTYPE html>
<html lang=zh-CN>
<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<title>生产运营2.0</title>
<script>
var coverSupport = 'CSS'in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')
</script>
<link rel=stylesheet href=./static/index.2da1efab.css>
</head>
<body>
<noscript>
<strong>Please enable JavaScript to continue.</strong>
</noscript>
<div id=app></div>
<script src=./static/js/chunk-vendors.bd1ef1be.js></script>
<script src=./static/js/index.78d3480f.js></script>
</body>
</html>
两者的差异主要在 src=/static/js/chunk-vendors.bd1ef1be.js 部分,打包的引起地址多了一个点,无论部署在哪一级目录下,如何用nginx转发都正常,运行模式时如果用ngnix转发到域名的二级目录下就无法正常加载 static下的资源。
manifest.json 中配置
"h5" : {
"title" : "生产运营2.0",
"router" : {
"base" : "./"
},
"sdkConfigs" : {
"maps" : {}
},
"devServer" : {
"https" : false,
"allowedHosts":["localhost","192.168.0.66","我的域名"]
}
}
需求:如何才能使得在 运行 时 生成的 index.html 中对static资源的引用路径也采用相对路径,就是在 /static/ 签名加上点
0 个回复