-
-
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
feat: build library new option - emitAssets #5028
Conversation
@Shinigami92 Provided a couple of tests :) |
@hronro would you help to review this PR? @torsteinringnes IIUC from the linked issue the idea was to apply this only when the output format is |
All it does is emitting image assets like with default build. I dont see why it only should be in |
@torsteinringnes However, in library mode, people may want to target different module systems (esm, commonjs, or whatever), and vite also allows people to do that. Obviously, |
We also need this feature. What was the problem with this pull request so it got closed? Is an additional check for es output sufficient for approval? |
@hronro
Is there some different for 1. |
Of course there is. Basically for applications (not libraries), we can use absolute path (please note relative path will not work), and this is why webpack's publicPath option exist. However for libraries, we have no ideas what the |
Without the ability to exclude binary assets like images, fonts etc. from being inlined in bundled code, there is no way to create library output compliant with security-conscious So using library mode in Vite currently enforces security holes with regard to CSP/cross-site scripting. This effectively rules out Vite.js as a build stack for security-sensitive environments.
The least thing that imo is an absolute necessity here is to allow asset inlining to be excluded from the generation of the CSS bundle. Instead of inlining those assets, allow an option to transform paths for excluded assets from DEVELOPMENT to PRODUCTION. |
@franktopel What do you mean by "allow an option to transform paths for excluded assets from DEVELOPMENT to PRODUCTION"? |
When assets are no longer inlined, we probably need an option to tell Vite that what is |
I totally agree with that. In the original issue ( #4454) I post, I said this is only for For other formats, I'm not sure if there is a way to do that. |
Fix: [#4454, #3295]
Description
If your environment disables you from using script modules, you have to use
lib:true
to build. This forces assets likejpg/png
to be encoded inline which causes bundle files to be huge.This PR introduces a new option
emitAssets:boolean
, by default assets will remain inline when not setting emitAssets.There are 2 relevant issue:
#3295
#4454
To test use
build.lib.emitAssets:true
in the vite.config.js.Expected results: Imported files like
.svg,.png.jpg
are emitted and referenced by their path in the js bundle.Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).