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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vite-plugin-goodscript

v0.4.0

Published

Vite plugin for GoodScript - compile -gs.ts files on-the-fly with full HMR support

Downloads

465

Readme

vite-plugin-goodscript

Vite plugin for compiling GoodScript files on-the-fly with full Hot Module Replacement (HMR) support.

Installation

npm install --save-dev vite-plugin-goodscript goodscript

Usage

Basic Setup (Any Framework)

// vite.config.ts
import { defineConfig } from 'vite';
import goodscript from 'vite-plugin-goodscript';

export default defineConfig({
  plugins: [
    goodscript({
      level: 'clean',  // Enforce GoodScript "clean" level (TypeScript good parts)
      include: ['**/*-gs.ts']
    })
  ]
});

With React

// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import goodscript from 'vite-plugin-goodscript';

export default defineConfig({
  plugins: [
    goodscript({
      level: 'clean',
      include: ['**/*-gs.ts', '**/*-gs.tsx']
    }),
    react()
  ]
});

With Vue

// vite.config.ts
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import goodscript from 'vite-plugin-goodscript';

export default defineConfig({
  plugins: [
    goodscript({
      level: 'clean',
      include: ['**/*-gs.ts']
    }),
    vue()
  ]
});

Options

level

  • Type: 'clean' | 'dag' | 'native'
  • Default: 'clean'

Language level to enforce:

  • 'clean': TypeScript good parts only (Phase 1 restrictions)
  • 'dag': Level 1 + ownership/DAG validation (Phase 2)
  • 'native': Full validation for native compilation (Phase 3)

include

  • Type: string[]
  • Default: ['**/*-gs.ts', '**/*-gs.tsx']

Glob patterns for files to process. Only files matching these patterns will be compiled by GoodScript.

exclude

  • Type: string[]
  • Default: ['node_modules/**']

Glob patterns for files to exclude from processing.

skipOwnershipChecks

  • Type: boolean
  • Default: false for level 'clean', true for 'dag'/'native'

Skip ownership analysis (Phase 2 checks). Automatically set based on level if not specified.

How It Works

  1. Vite intercepts -gs.ts and -gs.tsx files during module resolution
  2. GoodScript compiler validates and transforms them on-the-fly
  3. Generated TypeScript flows into subsequent plugins (React, Vue, etc.)
  4. Full HMR support - changes trigger recompilation and hot reload

Features

Real-time compilation during development
Full HMR support with file caching
Framework-agnostic - works with React, Vue, Svelte, vanilla TS, etc.
Proper error reporting in Vite's error overlay
Zero config for common cases
⚠️ Source maps (coming soon)

Example Project Structure

my-app/
├── src/
│   ├── main-gs.ts          # GoodScript entry point
│   ├── components/
│   │   ├── Button-gs.tsx   # React component in GoodScript
│   │   └── utils-gs.ts     # Utility functions
│   └── legacy/
│       └── old-code.ts     # Regular TypeScript (not processed)
├── vite.config.ts
└── package.json

Migration from CLI Workflow

If you're currently using gsc to pre-compile GoodScript files:

Before (CLI workflow):

{
  "scripts": {
    "build": "gsc && vite build",
    "dev": "concurrently \"gsc --watch\" \"vite dev\""
  }
}

After (Vite plugin):

{
  "scripts": {
    "build": "vite build",
    "dev": "vite dev"
  }
}

The plugin handles compilation automatically - no more generated .ts files cluttering your source tree!

Troubleshooting

TypeScript errors in -gs.ts files

Make sure your tsconfig.json includes the GoodScript type definitions:

{
  "compilerOptions": {
    "types": ["goodscript"]
  }
}

Plugin not processing files

Check that your file patterns match. The default is **/*-gs.ts and **/*-gs.tsx. If you're using different extensions, update the include option.

Performance issues with large projects

The plugin caches compiled results based on file modification time. If you experience slowness:

  1. Make sure you're not processing node_modules (excluded by default)
  2. Use more specific include patterns to limit processed files
  3. Consider using the CLI workflow for production builds

License

MIT

Links