-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An external img should not generate an import statement #8047
Comments
To reproduce the issue:
Or here's the same code running on stackblitz that can demonstrate the issue: You can see the erroneous output in the There are more details in the github repo link, and a |
Thanks @LinusBorg for getting my post into the correct repo. Thorsten already did some homework, which I am copy/pasting from the other place where I had opened the issue.
|
import noExistImg from "/img/aaaSMPTE-color-bars.png" if |
This is fixed in #6779, so if you specify |
Thanks @bluwy, I just tried out this workaround (in vite v2.9.8). But I didn't get it to work. Did I specify Here's what I changed in the vite configs: diff --git a/vite.config.ts b/vite.config.ts
index 7a073c5..8535119 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -18,7 +18,13 @@ export default defineConfig({
],
}
},
- plugins: [vue()],
+ plugins: [vue({
+ template: {
+ transformAssetUrls: {
+ includeAbsolute: false
+ }
+ }
+ })],
// resolve: {
// alias: {
// '@': fileURLToPath(new URL('./src', import.meta.url))
(Or see the entire vite.config.ts file in my workaround branch.) I get the exact same output with and without the workaround in the configs. Either way, running
Did I apply the workaround incorrectly? |
I think that you should not add these images to |
Okay, I gave that a shot:
import { fileURLToPath, URL } from 'url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
build: {
manifest: true,
rollupOptions: {
input: [
'src/entry-point-1.ts',
'src/entry-point-2.ts',
],
external: [
],
}
},
plugins: [vue({
template: {
transformAssetUrls: {
includeAbsolute: false
}
}
})],
}) But now I'm back to Rollup being unhappy with me:
|
did you update |
Whoops! I did not update the Using that workaround, the output looks correct now compared to the previous output, with the excess I pushed a branch showing this working. Thanks @LinusBorg and @bluwy . |
Describe the bug
Here's the setup.
Page1.vue
contains an external image that doesn't exist in this repo**:There's a
entry-point-1.ts
file which includes thePage1.vue
file, and that entry point file is specified as aninput
in thevite.config.ts
config. Thevite.config.ts
also has a rollup config that specifies that PNG to beexternal:
Expected Behavior
Run
npm run build
.After running
npm run build
, the generated.js
file should not attempt to import anything for that<img>
source, and the string literal/img/aaaSMPTE-color-bars.png
should be left intact when rendering that<img>
. That<img>
is expected to be completely external (honoring the rollup config), and should be ignored by any client code.Actual Behavior
The build does not ignore that
<img>
tag, and generates an import statement that expects that image file to be in a relativelocation, i.e. in the build output,
File
dist/assets/entry-point-1.e49989cd.js
:That import breaks at runtime on the client side. That import should not exist in the build output, and the rendering of the
"img"
tag should be a static string value rather than the imported variable (n
).Reproduction
https://github.com/bseib/vue-vite-external-static-image
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: