Registry / web-framework / vite-plugin-moonbit

vite-plugin-moonbit

JSON →
library0.2.1jsnpmunverified

Vite plugin for MoonBit that allows importing MoonBit modules with the mbt: prefix. Current stable version is 0.2.1. It supports JS and WASM-GC backends, auto-starts moon build --watch, provides HMR on file changes, source maps for .mbt files, and supports MoonBit workspaces/monorepos. Key differentiators include a MoonBit-native DSL parser for moon.pkg/moon.work, query suffixes (?worker, ?url, ?raw), experimental TypeScript bridge generation via mizchi/ts.mbt, and the ability to mix multiple backends in one project. It requires vite >=5.0.0 and ships TypeScript types.

npm install vite-plugin-moonbit
INSTALL
IMPORT
SIG · VITE-PLUGIN-MOONBI
V
vite-plugin-moonbit
web-frameworkjavascriptv0.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

moonbit
import { moonbit } from 'vite-plugin-moonbit'
import moonbit from 'vite-plugin-moonbit'
The plugin exports a named export 'moonbit'. Default import is not available; using it will result in undefined.
MoonbitPluginOptions
import { type MoonbitPluginOptions } from 'vite-plugin-moonbit'
import { MoonbitPluginOptions } from 'vite-plugin-moonbit'
Type imports require the 'type' modifier in TypeScript with isolatedModules enabled. This is a type exported for TypeScript users.
MoonbitTsBridgeOptions
import { type MoonbitTsBridgeOptions } from 'vite-plugin-moonbit'
Type export for the experimental tsBridge option. Available since v0.2.1.

Basic setup with JS backend: configure Vite plugin, then import MoonBit modules using the mbt: prefix.

// vite.config.ts import { defineConfig } from 'vite'; import { moonbit } from 'vite-plugin-moonbit'; export default defineConfig({ plugins: [ moonbit({ target: 'js', watch: true, showLogs: true, prefix: 'mbt:', }) ], }); // main.ts import { greet } from 'mbt:username/app'; greet();
Debug
Known issues
breakingDefault export removed in v0.2.0. Previously 'import moonbit from ...' now yields undefined.
fix
Use named import: import { moonbit } from 'vite-plugin-moonbit'
affects: >=0.2.0
deprecatedThe 'target' option previously accepted 'wasm' as an alias for 'wasm-gc'. This alias is deprecated and may be removed.
fix
Use 'wasm-gc' explicitly instead of 'wasm'.
affects: >=0.2.0
gotchaTypeScript path mappings must be manually configured for IntelliSense to resolve mbt: imports. Without them, TypeScript may complain about missing modules.
fix
Add to tsconfig.json: {"compilerOptions": {"paths": {"mbt:*": ["./node_modules/vite-plugin-moonbit/types/mbt.d.ts"]}}}
affects: >=0.1.0
gotchaThe tsBridge option is experimental and may change in future releases. Generated bridge packages may require manual adjustments.
fix
Review generated bridge code and pin plugin version if stability is critical.
affects: >=0.2.1
Errors
Common errors & fixes
TypeError: moonbit is not a function
Using default import instead of named import.
fix
Change to: import { moonbit } from 'vite-plugin-moonbit'
Cannot find module 'mbt:username/app' or its corresponding type declarations.
TypeScript cannot resolve the mbt: prefix without path mappings.
fix
Add to tsconfig.json compilerOptions.paths: { "mbt:*": ["./node_modules/vite-plugin-moonbit/types/mbt.d.ts"] }
Error: moon build command failed with exit code 1
MoonBit build failed; often due to missing moon toolchain or incorrect target.
fix
Ensure 'moon' is installed and run 'moon build --target js' manually to see detailed errors.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
viterequiredpeer dependency required to function as a Vite plugin
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
vite-plugin-moonbit — npm install vite-plugin-moonbit · libregistry