最近发现小程序跟H5打包后会都自动请求这张图片,上网查了一下。根据网上的解决方案,设置
"uniStatistics" : {
"enable" : false
}
后 还是没能去掉。求dalao指点迷津
最近发现小程序跟H5打包后会都自动请求这张图片,上网查了一下。根据网上的解决方案,设置
"uniStatistics" : {
"enable" : false
}
后 还是没能去掉。求dalao指点迷津
最佳回复
这个不是统计,关闭uni统计自然没用。
这个图片是导航栏底边阴影效果预加载加速显示用的,如果不需要参考下面的配置。
H5 平台:在起始页 html 文件中添加下面代码,参考 manifest H5 index.html 模板配置
<head>
<style>
body::after {
content: none !important;
}
</style>
</head>
a***@bulog.cn - Make it Simple Stupid
有需要的可以进行下面的替换。
使用方法,
background-image:url(https://cdn.dcloud.net.cn/img/shadow-blue.png);
替换为
background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAGBAMAAADwPukCAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAASUExURb7T9ezy/MbY9t/p tHg Pf6/gmQWsMAAAAUSURBVAjXY2BgUGBwYDBgEGAIAAAEXADx8btKYQAAAABJRU5ErkJggg==)
下面是各个颜色的Base64编码,需要对css文件逐个替换
https://cdn.dcloud.net.cn/img/shadow-blue.png
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAGBAMAAADwPukCAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAASUExURb7T9ezy/MbY9t/p+tHg+Pf6/gmQWsMAAAAUSURBVAjXY2BgUGBwYDBgEGAIAAAEXADx8btKYQAAAABJRU5ErkJggg==
https://cdn.dcloud.net.cn/img/shadow-green.png
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAGBAMAAADwPukCAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAASUExURb71vuz87Mb2xt/639H40ff+98iMtmEAAAAUSURBVAjXY2BgUGBwYDBgEGAIAAAEXADx8btKYQAAAABJRU5ErkJggg==
https://cdn.dcloud.net.cn/img/shadow-grey.png
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAGBAMAAADwPukCAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAASUExURdnZ2fT09N7e3uzs7OTk5Pr6+vVa4lkAAAAUSURBVAjXY2BgUGBwYDBgEGAIAAAEXADx8btKYQAAAABJRU5ErkJggg==
https://cdn.dcloud.net.cn/img/shadow-orange.png
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAGBAMAAADwPukCAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAASUExURfXTvvzy7PbYxvrp3/jg0f7692in75UAAAAUSURBVAjXY2BgUGBwYDBgEGAIAAAEXADx8btKYQAAAABJRU5ErkJggg==
https://cdn.dcloud.net.cn/img/shadow-red.png
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAGBAMAAADwPukCAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAASUExURfW+yvzs7/bG0Prf5PjR2v73+TToEXgAAAAUSURBVAjXY2BgUGBwYDBgEGAIAAAEXADx8btKYQAAAABJRU5ErkJggg==
https://cdn.dcloud.net.cn/img/shadow-yellow.png
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAGBAMAAADwPukCAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAASUExURfXvvvz67Pbxxvr33/j00f7997nVB7sAAAAUSURBVAjXY2BgUGBwYDBgEGAIAAAEXADx8btKYQAAAABJRU5ErkJggg==
可以使用自定义插件在编译后的文件中删除cdn资源引用源码的方式解决:
在根目录添加 "vue.config.js"
文件并配置以下代码:
module.exports = {
configureWebpack: (config) => {
// 编译后删除css文件里自带的uni-app资源引用
config.plugins.push(function (compiler) {
const pathReg = /\s*background(-image)?:\s*url\(\S*?\/\/[\w\.-]*?dcloud.net.cn\S*?\);?[ \t]*/gi
const eachReplace = (dirPath) => {
fs.readdirSync(dirPath, { withFileTypes: true }).forEach(dirent => {
const filePath = path.join(dirPath, dirent.name)
if (dirent.isDirectory()) {
eachReplace(filePath)
} else if (dirent.isFile() && /.(c|ac|wx)ss$/.test(dirent.name)) {
try {
const fileData = fs.readFileSync(filePath, 'utf8')
if (pathReg.test(fileData)) {
fs.writeFileSync(filePath, fileData.replace(pathReg, ''), 'utf8')
}
} catch (e) {}
}
})
}
compiler.hooks.done.tap('removeUniCdnPath', eachReplace.bind(null, process.env.UNI_OUTPUT_DIR))
})
}
}
SeasideLee
请问小程序平台要如何配置才能去掉 app.wxss 末尾自动添加的如下代码
page::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(https://cdn1.dcloud.net.cn/img/shadow-grey.png)}100%{background-image:url(https://cdn1.dcloud.net.cn/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(https://cdn1.dcloud.net.cn/img/shadow-grey.png)}100%{background-image:url(https://cdn1.dcloud.net.cn/img/shadow-grey.png)}}page{--status-bar-height:25px;--top-window-height:0px;--window-top:0px;--window-bottom:0px;--window-left:0px;--window-right:0px;--window-magin:0px}[data-c-h="true"]{display: none !important;}
2023-01-15 21:59
7***@qq.com
回复 SeasideLee: 小程序上有安全域名 可以不用管
2023-07-17 18:49
7***@qq.com
回复 7***@qq.com: 回复 SeasideLee: 或者在小程序的app.wxss里直接删除了也行
2023-07-17 18:58
SeasideLee
回复 7***@qq.com: 我现在就是直接删除的,但是很烦,每次提交新版本都得删除
2023-07-22 13:12
lihuifang
我怎么没找到这个 index.html 模板配置 麻烦直接贴下代码可以吗?我现在项目打包出的文件里也出现了cdn.dcloud.net.cn 头疼
2023-09-22 10:16