vite-plugin-instance
v0.1.0
Published
Vite integration for the Instance framework — boot-attribute script injection, .is file compilation through the real Instance Compiler, and the virtual:instance IVC module.
Maintainers
Readme
vite-plugin-instance
Vite integration for the Instance framework.
Instance is a no-build framework — one classic <script> that boots off its own
tag attributes. This plugin doesn't change that. It exists for projects already
living inside Vite, and does three things:
- Injects the Instance script into
index.htmlwith your boot attributes (⚡,autoclass,super, …), first in<head>, so thedocument.currentScriptboot contract works exactly like a hand-written tag. - Compiles
.isfiles (the Instance DSL) at dev/build time — through the real Instance Compiler booted headlessly, not a reimplementation — soimport './app.is'just works. - Serves
virtual:instance— a module retrieving the active Instance via the IVC broker (globalThis[Symbol.for('Instance')]()), so module code never depends on the named global.
Setup
npm i -D vite-plugin-instance
npm i -D jsdom # only needed if you use .is filesPut your Instance bundle (e.g. Instance-0.87.x.js) in public/.
// vite.config.js
import { defineConfig } from 'vite';
import instance from 'vite-plugin-instance';
export default defineConfig({
plugins: [
instance({
src: '/Instance-0.87.x.js',
attrs: { '⚡': true, autoclass: 'core, baseline' },
}),
],
});// any module
import Instance, { ready } from 'virtual:instance';
import './components/hello.is'; // compiled at build time
await ready;
document.body.appendChild(new Hello());Options
| option | default | meaning |
|--------------|--------------------------------|---------|
| src | /Instance-0.87.x.js | public path the bundle is served from |
| attrs | { autoclass: 'core, baseline' } | boot attributes on the injected tag; true renders a bare attribute |
| inject | true | set false if you hand-write the script tag |
| compileIs | true | set false to skip .is compilation |
| bundlePath | <publicDir> + src | filesystem path to the bundle, for the compiler boot |
Notes
- The injected tag is a classic script, deliberately — Instance's boot reads
document.currentScriptattributes, which ES modules don't have. It executes before any module code, sovirtual:instancealways finds a booted runtime. - Compiled
.ismodules are definition side-effects (classes register against the booted runtime); import them for effect. - No build step is required to publish or consume this plugin. It is three files.
