npm run dev ならエラーにならないが、
npm run build だとエラーになる。
原因は以下のコード
<img src="/img/seiya.jpg">
画像が見つかりませんよエラー
[vite]: Rollup failed to resolve import "/img/seiya.jpg" from "/var/www/html/renkatu.club/resources/js/components/Home.vue?vue&type=script&setup=true&lang.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "/img/seiya.jpg" from "/var/www/html/renkatu.club/resources/js/components/Home.vue?vue&type=script&setup=true&lang.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
at onRollupWarning (file:///var/www/html/renkatu.club/node_modules/vite/dist/node/chunks/dep-79892de8.js:46368:19)
at onwarn (file:///var/www/html/renkatu.club/node_modules/vite/dist/node/chunks/dep-79892de8.js:46138:13)
at Object.onwarn (file:///var/www/html/renkatu.club/node_modules/rollup/dist/es/shared/node-entry.js:25149:13)
at ModuleLoader.handleInvalidResolvedId (file:///var/www/html/renkatu.club/node_modules/rollup/dist/es/shared/node-entry.js:23784:26)
at file:///var/www/html/renkatu.club/node_modules/rollup/dist/es/shared/node-entry.js:23744:26
まじかよ
解決策
vite.configを以下のように書き換えるだけ
vue({
// This is needed, or else Vite will try to find image paths (which it wont be able to find because this will be called on the web, not directly)
// For example <img src="/images/logo.png"> will not work without the code below
template: {
transformAssetUrls: {
includeAbsolute: false,
},
},
}),