-
-
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
add an option to not to inline assets in library mode when format is 'es' #4454
Comments
+1 for that feature, In my case, I want to build a components library that includes fonts with that option, but now Vite includes the fonts in base64 string, after build, I see that my These are so huge for CSS and every new update of my CSS will be recached old file, but fonts are a more stable thing in the library and I can cache them for long days unlike |
@xesjkeee would you create another feature request for avoiding bundling the fonts in css files? Your proposal is a good idea to explore but it isn't directly related to this issue. Thanks! |
@hronro we discussed your proposal with the team and it sounds good. As you said, it should only be applied to |
Hello @hronro. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it! |
Besides from checking |
Is this going to be fixed? I see the PR was closed and wondering if this issue is still something the maintainers want to fix. I have a library built with vite that has an icon font. I'd rather not have the font inlined in css as that makes for a very large css file and effectively means those files can't be cached long term. It also means the browser is downloading all 3 font formats provided when it only needs to download the one it can/will use which is very inefficient. |
I also need this urgently, as we're about to launch our component library built with Vite, and our security engineer doesn't want us to allow Please upgrade the relevance of this feature as without it, people are forced to implement an inherently insecure setting for their |
Are there any updates on that? It seems like a very common use-case for libraries – barely anyone wants fonts to be inlined in CSS. |
I initialized a monorepo by rush recently. The monorepo has a vue app package and a vue component package. The key problem is the vue component package depend on a logo image. The key code is as below.
First time I use I have checked the vue component package's compiled code. The key code is as below.
So I guess webpack inside vue app package cannot detect the compiled vue component package depend on a logo png. Second time I changed to use vite to build the vue component package. And vite document said that it supports es and umd. But finally I find this issue. Vite inline all assets in library mode. 😢 So as a summary, we cannot use any image or other assets inside vue component. |
…this works for css… assets in
in
in
the
|
This would be amazing to have, for situations like the one I'm facing where I have a monorepo, with a shared codebase for frontend app logic and a web app and a separate electron app that both render that same shared codebase |
What @g10 suggested worked like a charm for the lib we're working on. Placing files in
|
Looking forward to have this option supported. We are currently working on a library including a large webassembly file(10M plus). |
+1 |
As the author of that plugin, I would love to know more about the issues you encountered so that I may attempt to fix them 🙂 The plugin does something very much like your solution, but it goes even further and doesn’t actually bundle anything - so unless you want that, it is probably not a good fit. Also, the plugin does not aim to resolve the problem in this issue, though it does have a |
I wrote a plugin to "external" assets in library mode: usage:
|
Pretty significant that Vite doesn't have this feature yet. Webpack had |
I had the same problem, I tried to compile a vue3 project and keep the directory structure, publish to npm repository. I split a project into monorepo. no idea yet |
This problem has been bothering me for a long time. Is there any update? |
Any updates on the issue? Can't start using |
Thank you! In meanwhile I've managed to workaround by using |
I have a monorepository with several UI libraries in react used by applications outside this monorepository. What would be the simplest workaround for a use case where I use images, fonts and videos from within the same library? I thought about leaving the files in the public folder, and in the application, changing the path of the public folder to node_modules/@my-org/my-lib/assets, but then I would need to create another assets folder inside public, otherwise when building the library folders inside public will go to the root of the outDir, and the vite public folder configuration parameter only accepts a single string and that would prevent the application from adding more files. I remember reading somewhere that maybe using an exclusive package for these assets might work, but I don't understand how. |
I wrote a plugin to emit external files in library mode: vite-plugin-lib-assets |
Using the following syntax manages to create seperate file for each asset but it modularizes them and in doing so it encodes them in base64 again. Extra steps for the same thing?
await import("../bin/foo.js?url").then(m => m.default) Weirdly enough, I have a worker file that's being imported in the following syntax. That however, places the related worker file under import FooWorker from "./worker?worker&url"
new Worker(new URL(FooWorker, import.meta.url).href, {
type: "module"
}) Now, to an extent I could understand why library mode differs from standalone mode. However, within same mode why does this asset bundling differ? Either putting the worker under assets was a mistake or this is possible from the start but the first syntax I've pointed out is being neglected. Or there is another syntax which would work in the same way as how workers are being bundled. If someone could shine a light on this that would be delightful. |
@rijenkii Have you managed to do something with that? I've noticed that we have exactly the same problem that you mentioned :/ |
@zgrybus Well, kind of, but not really. Currently using something like this: import pkg from "./package.json";
const deps = [...Object.keys(pkg.dependencies), ...Object.keys(pkg.peerDependencies)];
export default defineConfig({
build: {
rollupOptions: {
external: (source) => {
for (const dep of deps) {
if (source === dep || source.startsWith(`${dep}/`)) {
return true;
}
}
return false;
},
},
},
}); This allows the usage of aliases, but may fail if you accidentally import something from a transitive dependency that is not explicitly defined in the |
My setup consist of two Vite build configs. Ended up disabling lib mode and using export default defineConfig({
build: {
lib: false,
rollupOptions: {
input: { /* ...assets */ },
output: {
assetFileNames: ({ name }) =>
name ? name : 'assets/[name]-[hash][extname]'
}
},
},
}); And then I have another config for the non assets, making sure I correctly alias the paths to the asset build files. As long you don't bundle those files into your JS, you're good to go... |
Still having this problem in 2025, I am trying to make vite not inline a |
@marcofugaro There's a way with vite 6:
This method doesn't work for js files though. Importing a js file using |
Clear and concise description of the problem
Currently when using library mode, all the assets (images, videos...) are inlined using base64. When those assets are big, it takes a long for vite to build, and the browser also takes a long time to parse the javascript.
Suggested solution
When the library format is 'es', we can add an option to make vite emit those files, and import those files in javascript using
new URL(import.meta.url, '...')
, e.g.Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: