-
-
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
allow configuring the crossorigin attribute #6648
Comments
related: #4453 |
I'm not sure about allowing another set of config to workaround a browser bug, since the issue has been 2 years and counting, perhaps it's fine to follow the correct spec instead. Another solution is to check |
create a vite plugin to replace
|
There is a similar issue on Firefox. The above plugin workaround wouldn't work for It'd be good to handle non-chrome browsers in the polyfill or add a vite option to allow explicitly setting the Are there any plans to address this soon? Our production builds are affected by this. Currently, working around it with forked Vite with |
I was looking for a way to remove the |
Came up with this temporary workaround export default defineConfig({
plugins: [
{
name: 'crossorigin',
transformIndexHtml(html) {
return html.replace(/crossorigin/g, 'crossorigin="use-credentials"');
},
},
{
generateBundle(options, bundle) {
for (const url in bundle) {
// 2. Then replace `crossOrigin`
if (bundle[url].name === 'helper') {
bundle[url].code = bundle[url].code.replace(
'crossOrigin=""',
'crossOrigin="use-credentials"'
);
}
}
},
},
],
build: {
rollupOptions: {
output: {
manualChunks(id) {
// 1. Split vite scripts into a separate chunk
if (id.startsWith('\u0000vite')) {
return 'helper';
}
},
},
},
},
}); |
nice 👍 I made a change based on this, others can also refer to it plugins: [
{
name: 'vite:crossorigin-use-credentials',
transformIndexHtml(html) {
return html.replace(/crossorigin/g, 'crossorigin="use-credentials"');
},
generateBundle(_, bundle) {
for (const url in bundle) {
if (bundle[url].name === 'preload-helper') {
// @ts-ignore
bundle[url].code = bundle[url].code.replace(
'crossOrigin = ""',
'crossOrigin = "use-credentials"'
);
}
}
}
}
],
build: {
rollupOptions: {
output: {
manualChunks(id) {
// Extract virtual module
if (id === '\0vite/preload-helper.js') {
return 'preload-helper';
}
}
}
}
} |
Clear and concise description of the problem
When building, the script tags inside the dist index.html get the attribute crossorigin automatically. The only way to change it to "use-credentials" is by modifying the final dist file.
The reason this should be able to be modified is because there is a bug in Safari which leads to an 401 HTTP error if you have any authentication. https://bugs.webkit.org/show_bug.cgi?id=171566
Suggested solution
It would be nice to set crossorigin="use-credentials" inside vite.config.js somewhere for modules.
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: