vite 打包new URL 失效 静态图片没有打包进去
2023-07-05 本文已影响0人
还好还好L
![](https://img.haomeiwen.com/i14882258/736d3ce8bd456f7b.png)
如图官方写法
function getImageUrl(name) {
return new URL(`./dir/${name}.png`, import.meta.url).href
}
我的写法
export default function (imagePath: string) {
return new URL("../assets/imgs/"+imagePath, import.meta.url).href;
}
第一反应没有什么问题吧。但是打包出来第一种写法会被正常编译,第二种不会?????
上github copilot结果
![](https://img.haomeiwen.com/i14882258/5c482775481ab4cb.png)