-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Options for assets building without adding hash #378
Comments
@FateRiddle Same as #329 but it's tracked with the library configuration preset here #330. |
After some search inside the codebase, I've found the line where the all the magic happen for the CSS (line 174) : vite/src/node/build/buildPluginCss.ts Lines 168 to 185 in 1e375a4
Currently, as we can see, it's hardcoded and we can hope for an option in the futur. For now there is no workaround w/ Vite but you could choose to build your app with rollup directy without vite. For the JS you could add a configuration option : module.exports = {
... // other configs options
rollupOutputOptions: {
entryFileNames: '[name].js',
}
} |
@underfin following the Contributing Guide, I could make a small workaround in a PR by extending |
After some investigations Maybe it could be interesting to make a @underfin have you an opinion on that point ? |
I'm in urgent need for this to be resolved. I could help or submit a PR if no one else is already working on this. |
I made the change locally I could submit a PR (ETA tomorrow) |
My PR is on the way :) wait and see ! |
` vite/src/node/build/buildPluginCss.ts // const cssFileName = `style.${hash_sum(staticCss)}.css`
// bundle[cssFileName] = {
// name: cssFileName,
// isAsset: true,
// type: 'asset',
// fileName: cssFileName,
// source: staticCss
// }
Object.keys(bundle).forEach((b) => {
if (!b.includes("runtime-dom.esm-bundler")) {
const t = b.split("/")[1].replace(".js", "");
if (t && !t.includes("runtime-dom.esm-bundler")) {
const t = b.split("/")[1].replace(".js", "");
const cssFileName = `${t}/${t}.css`;
bundle[cssFileName] = {
name: cssFileName,
isAsset: true,
type: "asset",
fileName: cssFileName,
source: staticCss,
};
}
}
}); ` Add these lines to generate the shared css file at every bundle path defined without hash and the bundle name. Hope it helps someone. |
1. generate asset by `emitFile` and format file name by rollup options. 2. use `rollup.write` instead of `rollup.generate`, let many rollup plugins can work with `writeBundle` hook. fix vitejs#880, fix vitejs#912, fix vitejs#378
With #957 merged you can customize it via rollupOutputOptions: {
entryFileNames: `[name].js`,
chunkFileNames: `[name].js`,
assetFileNames: `[name].[ext]`
} |
For Vite 2 and newbies out there... this setting now looks like this: vite.config.ts export default defineConfig({
plugins: [vue()],
build: {
rollupOptions: {
output: {
entryFileNames: `assets/[name].js`,
chunkFileNames: `assets/[name].js`,
assetFileNames: `assets/[name].[ext]`
}
}
}
}) |
This seems to work for |
Yeah, even for the start project I still get entryFileNames: `[name].js`,
chunkFileNames: `[name].js`,
assetFileNames: `[name].[ext]` |
@AlttiRi would you create a new issue with a small reproduction so this can be properly tracked? |
also for legacy js files, generated by
|
I'm having the same problem right now, it doesn't seem like there's a solution for the legacy js files. My use case is that I want to build my assets with vite and then serve them over a CDN, so i cannot have changing file names over versions. |
If you are looking for a temporary solution if using docker or something different for your builds, you can simply run this small bash script to rename the file after build.
|
Can I ask what exactly is meant by "Legacy JS Files"? |
scroll 4 posts up |
This issue has been locked since it has been closed for more than 14 days. If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Vite version. If you have any other comments you should join the chat at Vite Land or create a new discussion. |
I'm trying to make a library builder out of
create-vite-app
, and it is close to useable with one last step, here's theprod.config.js
file :The build result will be in
dist
and look like this:So I want
src/App.jsx
to be built intoindex.js
rather thanindex.8d84e296.js
.Can this be supported?
The text was updated successfully, but these errors were encountered: