A vite plugin for enabling cross-origin-isolation for dev server.
Cross origin isolation
is required for SharedArrayBuffer
.
Using this plugin, in local dev server, functions that rely on SAB can be enabled and tested.
Edit 2023:
The motivation of this plugin was mainly for my project Glicol: a collaborative music programming language
But now there are some "official" ways to do it, see here.
First install it in your vite project:
npm i -D vite-plugin-cross-origin-isolation
Then, in vite.config.js
:
import crossOriginIsolation from 'vite-plugin-cross-origin-isolation'
export default {
plugins: [
// other plugins...
crossOriginIsolation()
]
}
If this doesn't work, try this instead:
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
{
name: "configure-response-headers",
configureServer: (server) => {
server.middlewares.use((_req, res, next) => {
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
next();
});
},
},
],
});
Copy from: vitejs/vite#3909 (comment)
The MIT License (MIT)
Copyright (c) 2021 - present Qichao Lan (chaosprint)