Skip to content

hyperpolymath/rescript-vite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

rescript-vite

A language evangeliser Vite plugin with a pluggable adapter system. ReScript is the primary language with zero-config, all-pain-points-solved support. AffineScript is the secondary language. The adapter protocol is designed so that any language can be added, and the whole system integrates into PanLL’s language development workspace.

What is rescript-vite?

rescript-vite started as the definitive Vite plugin for ReScript — zero-config, every known pain point solved. It has since evolved into a multi-language evangeliser with a pluggable adapter protocol.

For ReScript users

Just use it. Zero config. Everything is auto-detected.

// vite.config.js
import rescriptPlugin from "rescript-vite";
export default { plugins: [rescriptPlugin()] };

For multi-language projects

Add language adapters for projects that mix ReScript with AffineScript (or future languages):

// vite.config.js
import { makeWithAdapters } from "rescript-vite";
import { make as affinescriptAdapter } from "rescript-vite/adapter/affinescript";

export default {
  plugins: [
    makeWithAdapters({
      adapters: [affinescriptAdapter()],
    }),
  ],
};

Features

  • Zero configplugins: [rescriptPlugin()] and you’re done. Everything is auto-detected from rescript.json.

  • Multi-language support — Pluggable adapter protocol. ReScript built-in, AffineScript included, any language can be added.

  • PascalCase module resolution — Fixes the #1 Linux pain point where ReScript emits lowercase imports but actual files are PascalCase on disk.

  • Auto optimizeDeps exclusion — Merged across all active language adapters.

  • Build artifact watcher ignore — Merged across all active adapters.

  • rescript.json auto-detection — Reads suffix, module format, in-source setting.

  • Rewatch support — Auto-detects rewatch binary (ReScript 12+).

  • Automatic compiler management — Spawns compilers for all active languages.

  • HMR for all languages — Routes file changes to the correct adapter by extension.

  • Error overlay integration — Pushes diagnostics from any adapter to Vite’s overlay.

  • ANSI color forwardingNINJA_ANSI_FORCED=1 for colored output.

  • In-source: false support — Correctly maps out-of-source compilation.

  • Deno compatible — Auto-detects the Deno runtime.

  • BoJ build orchestration — Optionally delegates to a BoJ ssg-mcp cartridge.

  • All features toggleableautoOptimizeDeps, autoResolve, autoIgnoreArtifacts.

  • panic-attacker compatible — Diagnostic format maps to SARIF output.

Installation

Using Deno

deno add npm:rescript-vite

Using npm (where Deno is not available)

npm install rescript-vite

Peer dependencies

rescript-vite expects these as peer dependencies:

  • rescript ^12.0.0

  • @rescript/core ^1.0.0

  • vite ^6.0.0

Usage

Basic setup (ReScript only)

// vite.config.js
import rescriptPlugin from "rescript-vite";

export default {
  plugins: [rescriptPlugin()],
};

With options

// vite.config.js
import { make } from "rescript-vite";

export default {
  plugins: [
    make({
      useDeno: true,
      logLevel: "verbose",
      compilerFlags: ["-warn-error", "+a"],
    }),
  ],
};

With AffineScript

// vite.config.js
import { makeWithAdapters } from "rescript-vite";
import { make as affinescriptAdapter } from "rescript-vite/adapter/affinescript";

export default {
  plugins: [
    makeWithAdapters({
      adapters: [affinescriptAdapter()],
      logLevel: "info",
    }),
  ],
};

With BoJ build orchestration

// vite.config.js
import { make } from "rescript-vite";

export default {
  plugins: [
    make({
      boj: true,
      bojEndpoint: "http://localhost:7077/mcp/ssg",
      logLevel: "info",
    }),
  ],
};

API Reference

make(options?)

Creates a Vite plugin instance with ReScript support (and optional extra adapters). Returns a standard Vite plugin object with name: "rescript-vite" and enforce: "pre".

Options

Option Type Description Default

adapters

LanguageAdapter.t[]

Additional language adapters beyond the built-in ReScript support. Each adapter teaches the plugin how to handle a different language.

[]

boj

boolean

Enable BoJ ssg-mcp build orchestration.

false

bojEndpoint

string

URL of the BoJ ssg-mcp cartridge endpoint.

http://localhost:7077/mcp/ssg

useDeno

boolean

Use Deno to run the ReScript compiler.

Auto-detected

rescriptBin

string

Path to the rescript binary.

undefined (uses npx)

compilerFlags

string[]

Extra flags passed to the ReScript compiler.

[]

logLevel

"silent" | "info" | "verbose"

Controls console output verbosity.

"info"

suffix

string

Output suffix override (e.g., ".res.mjs").

Auto-detected

useRewatch

boolean

Use rewatch instead of rescript build -w for watch mode.

Auto-detected

autoOptimizeDeps

boolean

Auto-exclude packages from all active adapters from Vite’s dependency pre-bundling.

true

autoResolve

boolean

Auto-resolve module imports (PascalCase for ReScript, adapter-specific for others).

true

autoIgnoreArtifacts

boolean

Auto-ignore build artifacts from all active adapters in Vite’s file watcher.

true

makeWithAdapters(options?)

Alias for make — identical function, named for clarity when using adapters.

Package exports

Export Module

rescript-vite

Main plugin (VitePluginRescript)

rescript-vite/config

ReScript config reader (RescriptConfig)

rescript-vite/boj

BoJ bridge (BojBridge)

rescript-vite/adapter

Language adapter protocol (LanguageAdapter)

rescript-vite/adapter/rescript

ReScript adapter (RescriptAdapter)

rescript-vite/adapter/affinescript

AffineScript adapter (AffineScriptAdapter)

Language Adapter Protocol

To add support for a new language, create a module implementing LanguageAdapter.t:

// my-language-adapter.js
export function make() {
  return {
    id: "my-language",
    displayName: "My Language",
    extensions: [".ml"],
    detect: (root) => { /* return config path or undefined */ },
    readConfig: (root) => { /* return languageConfig */ },
    defaultConfig: { language: "my-language", suffix: ".ml.js", ... },
    getOutputPath: (config, sourceFile) => sourceFile + ".js",
    build: async (root, config) => { /* return buildResult */ },
    watch: (root, config) => { /* return { stop: () => {}, stopped: false } */ },
    parseDiagnostics: (output) => { /* return diagnostic[] */ },
    resolveImport: (source, importer, config) => undefined,
    excludePackages: [],
    artifactIgnorePatterns: ["**/_build/**"],
  };
}

Adapter lifecycle

  1. Detectiondetect(root) is called during config and configResolved hooks. If it returns a path, the adapter is activated.

  2. ConfigurationreadConfig(root) parses the language’s config file.

  3. Buildbuild(root, config) runs a one-shot compile. watch(root, config) starts the compiler in watch mode.

  4. HMR — When a file matching the adapter’s extensions changes, getOutputPath maps it to compiled output for Vite’s module graph.

  5. ResolutionresolveImport is called for imports that ReScript’s PascalCase resolver doesn’t handle.

  6. Cleanup — Watch handles are stopped during closeBundle.

Development

Build

just build
# or: deno task res:build

Test

just test
# or: deno test --no-check --allow-all tests/

Smoke test

just test-smoke

Future: PanLL Integration

This plugin is designed to become a PanLL panel for language development. The adapter protocol will be the standard way PanLL discovers and manages language toolchains across database, language, and protocol development workspaces.

AffineScript will eventually split into a standalone affinescript-vite package, leaving rescript-vite as the ReScript-focused plugin with a shared adapter protocol published as a spec.

License

PMPL-1.0-or-later (Palimpsest License).

See LICENSE for the full text.

Author

Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>

About

Vite plugin for ReScript with BoJ SSG-MCP integration — HMR, error overlay, diagnostic parsing

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors