Closed FatehAK closed 1 year ago
@FatehAK could you please provide the file/folder structure of your project?
It looks like this:
Still can't reproduce this, if you are using the image directly (using <img>
tag) inside index.html
or related components, the exclude
option should work as expected.
File hash generated by Vite should have no impact with comparison check.
could you please provide more details or a sample project?
I'm using an <img>
tag inside index.html. You can take a look at this repo -
Okay, I think I know where the problem is...
Vite 4 bundles things differently than Vite 2/3, The filename will be <filename>-<hash>.<ext>
instead of <filename>.<hash>.<ext>
.
for a temporary solution, you can downgrade vite to 3.2.5
from 4.0.0
, just run npm i vite@3
.
I'll see if I could do something to round this up!
Nice catch! No wonder the slicing logic worked fine you would have had 3 elements in the array earlier.
I found a solution in https://github.com/vitejs/vite/issues/378, basically you can add something in your vite.config.js
like this if you still want to use Vite 4:
import vsharp from "vite-plugin-vsharp"
export default ({
// ⬇️ from here
build: {
rollupOptions: {
output: {
assetFileNames: `assets/[name].[hash].[ext]`
}
}
},
// ⬆️ to here
plugins: [
vsharp()
]
})
not very elegant, but it works. 🥲
https://rollupjs.org/guide/en/#outputassetfilenames
Seems like Vite 4.0 upgraded to Rollup 3.0 which has changed the default asset names.
Is it possible to handle this within the vsharp plugin itself? Since everyone would have to make the path change to assets/[name].[hash].[ext]
😕
This is now fixed at version >1.4
, you can upgrade the vsharp plugin and delete the config items. 😆
The option to exclude certain files does not seem to work. I checked the source code it seems you are splicing the entire array and removing all the entries by
thisName.splice(0, 2);
as a result thisName ends up being an empty string.Also, lets say I give exclude like so -
exclude: ['thumbsup.gif']
When running
vite build
the filename contains the hash as well so the output of_path["default"].basename(el).split('.')
would be thumbsup-[hash].gifThis will fail the comparison check
opts.exclude.includes(thisName + thisExt)