Skip to content

milahu/vite-plugin-tree-sitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vite-plugin-tree-sitter

This plugin for vite streamlines the process of developing and bundling a tree-sitter grammar in your project.

Installation

Hosted on jsr. Installation instructions for supported platforms are described there.

Changelog

  • 0.3.1 2026-01-19 : updated documentation and examples
  • 0.3.0 2026-01-17 : upgraded dependencies
    • removed special handling for web-tree-sitter (0.26 no longer requires it)
  • 0.2.10 2025-06-21 : added CLI mode to node implementation
  • 0.2.9 2025-05-27 : adding interactive CLI mode (tree-sitter > 0.25)
  • 0.2.8 2025-01-15 : correcting node support for production mode output
  • 0.2.7 2024-12-27 : updated documentation and examples
  • 0.2.6 2024-12-27 : replaced indirection for createReadStream due to strange vite behavior
  • 0.2.5 2024-12-26 : modified some internal path tracking to absolute to remove ambiguity
  • 0.2.4 2024-12-26 : added fs method discriminators
    • currently supporting deno and node
    • added TRACE log level for better narrowing of issues
  • 0.2.3 2024-12-25 : replaced most node behaviors with native deno
  • 0.2.2 2024-12-25 : added support for legacy grammar definitions
    • attempt is made to upgrade a grammar before giving up
    • added pnpm example usage
  • 0.2.1 2024-12-24 : cleanup for jsr publish
    • added deno example
    • corrected error with detection of tree-sitter-cli tool location
    • added type documentation
  • 0.2.0 2024-12-24 : major refactor
    • use tree-sitter-cli instead of replicating it's behavior locally
    • project converted to deno
  • 0.1.3 2024-11-10 : updated emcc flags in compilation step
    • added option to set build cache location
    • added option to set serve cache location
  • 0.1.2 2024-11-07 : corrected behavior in vite 5
  • 0.1.1 2024-11-06 : corrected path handling for non-package grammars
  • 0.1.0 2023-07-09 : added output caching
    • support grammars without a scanner component
  • 0.0.1 2022-06-11 : initial release

Operation

You may either add the tree-sitter-cli tool to your project as a package dependency or have it installed locally and included on the PATH. This plugin will detect either scenario. You can then include some tree-sitter grammar as a package dependency or add it locally in a relative folder (in or outside of your project).

As a part of the vite rollup lifecycle, your grammar will be compiled using tree-sitter-cli and served automatically by your development server.

When bundling for production the generated wasm files are included in the distribution.

Configuration

// your project's vite.config.ts file

import { defineConfig } from "vite"
import pluginTreeSitter from "vite-plugin-tree-sitter"

export default defineConfig({
 plugins: [
  pluginTreeSitter(["../../github/tree-sitter-sqlite/"], {
   alwaysRebuild: false,
   emBuildCacheDir: null,
   wasmCacheDir: ".grammar",
   logLevel: "INFO",
  }),
 ],
 // following is required for web-tree-sitter.wasm to appear in dev-mode
 // until https://github.com/vitejs/vite/issues/8427 is addressed
 optimizeDeps: { exclude: ["web-tree-sitter"] },
})

Example

solidjs framework, based on solidjs template

see examples/solidjs/

External References

Similar projects

Related

About

bundle tree-sitter modules with vite

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors