Skip to content

chaosprint/vite-plugin-cross-origin-isolation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

vite-plugin-cross-origin-isolation

A vite plugin for enabling cross-origin-isolation for dev server.

Why

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.

Usage

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)

License

The MIT License (MIT)

Copyright (c) 2021 - present Qichao Lan (chaosprint)

About

A vite plugin for enabling cross-origin-isolation for dev server.

Resources

License

Stars

Watchers

Forks