npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thijsbroersen/vite-plugin-scalajs

v2.0.8

Published

Vite plugin for integration of Scala.js

Downloads

35

Readme

Vite Plugin for Scala.js

A Vite plugin that integrates Scala.js projects built with either SBT or Mill build tools. This plugin automatically watches your Scala.js output directories and triggers Vite reloads when files change, making development seamless.

Features

  • Multi-build tool support: Works with both SBT (1.x and 2.x) and Mill
  • Automatic file watching: Watches Scala.js output directories and triggers Vite reloads
  • Development and production modes: Supports both fast and full linking
  • Flexible configuration: Multiple projects with different build tools
  • Throttled reloads: Prevents excessive reloads during rapid file changes
  • Backward compatibility: Maintains compatibility with existing SBT-only setups

Installation

pnpm add -D @thijsbroersen/vite-plugin-scalajs
# or: npm install -D @thijsbroersen/vite-plugin-scalajs

Peer dependency: Vite 5, 6, 7, or 8 (install vite in your project).

Quick Start

SBT Project

import { defineConfig } from 'vite';
import { scalajsPlugin } from '@thijsbroersen/vite-plugin-scalajs';

export default defineConfig({
  plugins: [
    scalajsPlugin({
      projects: [
        {
          projectID: 'myProject',
          buildTool: {
            tool: 'sbt'
          }
        }
      ]
    })
  ]
});

Mill Project

import { defineConfig } from 'vite';
import { scalajsPlugin } from '@thijsbroersen/vite-plugin-scalajs';

export default defineConfig({
  plugins: [
    scalajsPlugin({
      projects: [
        {
          projectID: 'example',
          buildTool: {
            tool: 'mill'
          }
        }
      ]
    })
  ]
});

Mixed SBT and Mill Projects

import { defineConfig } from 'vite';
import { scalajsPlugin } from '@thijsbroersen/vite-plugin-scalajs';

export default defineConfig({
  plugins: [
    scalajsPlugin({
      projects: [
        {
          projectID: 'backend',
          buildTool: {
            tool: 'sbt'
          }
        },
        {
          projectID: 'frontend',
          buildTool: {
            tool: 'mill'
          }
        }
      ]
    })
  ]
});

Configuration Options

Plugin Options

  • projects: Array of Scala.js project configurations
  • projectRoot: Root directory of the Scala project (auto-detected if not provided)
  • cwd: Working directory for build tool commands (optional)
  • reloadThrottleMs: Minimum time in milliseconds between file change reloads (default: 2000)

Project Configuration

  • projectID: Project identifier (used for URI prefix and build tool targeting)
  • buildTool: Build tool configuration
    • tool: Either 'sbt' or 'mill'
    • script: Custom script name (optional, defaults to 'sbt' or 'mill')
  • uriPrefix: Custom URI prefix for imports (optional, defaults to projectID:)

Usage in Code

Import Scala.js modules using the configured URI prefix:

// Using projectID as prefix (default)
import 'myProject:main.js';

// Using custom prefix
import 'custom:main.js';

Development vs Production

The plugin automatically detects the Vite mode:

  • Development: Uses fastLinkJS (SBT) or fastLinkJS (Mill)
  • Production: Uses fullLinkJS (SBT) or fullLinkJS (Mill)

Examples

Getting Started

Working Examples

  • test/mill-project/: Mill-based Scala.js project with Vite configuration
  • test/sbt-project/: SBT 1.x-based Scala.js project with multiple modules
  • test/sbt-2-project/: SBT 2.x-based Scala.js project with multiple modules

Complete Example: Mill Project

// vite.config.ts
import { defineConfig } from 'vite';
import { scalajsPlugin } from '@thijsbroersen/vite-plugin-scalajs';

export default defineConfig({
  plugins: [
    scalajsPlugin({
      projects: [
        {
          projectID: 'example',
          buildTool: {
            tool: 'mill',
            script: './mill-assembly.jar' // optional, defaults to './mill'
          },
          uriPrefix: 'millexample' // optional, defaults to projectID
        }
      ]
    })
  ]
});
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
  <title>Scala.js + Vite</title>
</head>
<body>
  <div id="app"></div>
  <script type="module" src="/src/main.js"></script>
</body>
</html>
// src/main.js
import 'mill.example:main.js';

// Your JavaScript code here
console.log('Hello from Vite + Scala.js!');

API Reference

Types

  • ScalaJSPluginOptions: Main plugin configuration
  • ScalaJSProject: Individual project configuration
  • BuildTool: Union type for SBT or Mill build tools
  • SbtBuildTool: SBT-specific configuration
  • MillBuildTool: Mill-specific configuration

Functions

  • scalajsPlugin(options): Main plugin function

Troubleshooting

Common Issues

  1. Build tool not found: Ensure SBT or Mill is installed and available in your PATH or that the script config refers to the correct file
  2. Output directory not found: The plugin waits for build tools to create output directories
  3. Excessive reloads: Adjust reloadThrottleMs to reduce reload frequency
  4. Import resolution fails: Check that your uriPrefix or projectID is correct and that the script exists the output directory

Debug Mode

Enable debug logging by setting the DEBUG environment variable:

DEBUG=1 npm test

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

Apache 2.0