我有一个 Laravel 项目,在
public/images
文件夹中包含一些图像。我可以通过请求轻松加载 https://[domain]/images/[fileName]
我还有一个用 vite 构建的 Vue 组件,它只使用外部可用的图像:
<template>
...
<img src="/images/[fileName]" />
...
</template>
当我尝试使用
yarn build
构建文件时,我收到以下 vite 错误:
[vite]: Rollup failed to resolve import "/images/[fileName]" from "[projectRoot]/resources/js/VueComponent.vue".
This is most likely unintended because it can break your application at runtime.
我知道 Vite 正在尝试为我处理该文件,但他不知道在哪里可以找到它以便将其包含在输出文件夹中。
如何告诉 Vite 不这样做,并忽略图像路径的资产捆绑?
如果您正在关注 Laravel 文档,但拥有较新版本的 Vite,那么您需要...
更改此:
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
对此:
vue({
template: {
transformAssetUrlsOptions: {
base: null,
includeAbsolute: false,
},
},
}),