JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 48
  • Score
    100M100P100Q40363F
  • License MIT

A Vite plugin for Google Apps Script development with TypeScript support

Package Exports

  • vite-plugin-gas

Readme

vite-plugin-gas

A Vite plugin for Google Apps Script development with TypeScript support.

Features

  • ๐Ÿš€ Individual file compilation - Compiles each TypeScript file separately for GAS compatibility
  • ๐Ÿ”„ Module statement removal - Removes import/export statements that are not supported in GAS
  • ๐Ÿ›ก๏ธ GAS function protection - Protects special GAS functions (onEdit, onOpen, etc.) from being minified
  • โšก TypeScript support - Full TypeScript support with GAS API type definitions
  • ๐ŸŽฏ ES5 compatibility - Targets ES5 for maximum GAS compatibility

Installation

npm install vite-plugin-gas --save-dev
# or
pnpm add vite-plugin-gas -D
# or
yarn add vite-plugin-gas --dev

Usage

ๆœ€ใ‚‚ใ‚ทใƒณใƒ—ใƒซใชไฝฟ็”จๆ–นๆณ•ใงใ™ใ€‚ใƒ—ใƒฉใ‚ฐใ‚คใƒณใŒ่‡ชๅ‹•็š„ใซ src/ ใƒ‡ใ‚ฃใƒฌใ‚ฏใƒˆใƒชๅ†…ใฎTSใƒ•ใ‚กใ‚คใƒซใ‚’ๆคœๅ‡บใ—ใพใ™๏ผš

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

export default defineConfig({
  plugins: [
    gas({
      entryDir: 'src',  // TSใƒ•ใ‚กใ‚คใƒซใ‚’ๆคœ็ดขใ™ใ‚‹ใƒ‡ใ‚ฃใƒฌใ‚ฏใƒˆใƒช
      target: 'es5'     // GASไบ’ๆ›ใฎใŸใ‚ES5ๆŽจๅฅจ
    })
  ]
})
๐Ÿ“ Project Structure:
src/
โ”œโ”€โ”€ main.ts       # โ†’ dist/main.js
โ”œโ”€โ”€ utils.ts      # โ†’ dist/utils.js
โ”œโ”€โ”€ triggers.ts   # โ†’ dist/triggers.js
โ””โ”€โ”€ lib/
    โ””โ”€โ”€ helper.ts # โ†’ dist/lib_helper.js

๐Ÿ”ง Manual Configuration

ๆ‰‹ๅ‹•ใงใ‚จใƒณใƒˆใƒชใƒผใƒใ‚คใƒณใƒˆใ‚’ๆŒ‡ๅฎšใ—ใŸใ„ๅ ดๅˆ๏ผš

// vite.config.ts
export default defineConfig({
  plugins: [gas()],
  build: {
    rollupOptions: {
      input: {
        main: 'src/main.ts',
        utils: 'src/utils.ts'
      }
    }
  }
})

Configuration Options

Option Type Default Description
target 'es5' | 'es2015' 'es5' JavaScript output target
entryDir string 'src' Input directory to scan for TypeScript files
outputDir string 'dist' Output directory
compatCheck boolean true Enable GAS compatibility checks
replaceLogger boolean false Replace console.log with Logger.log
removeModuleStatements boolean true Remove import/export statements
preserveGasFunctions boolean true Protect GAS special functions from minification

Project Structure

my-gas-project/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.ts          # Main functions
โ”‚   โ”œโ”€โ”€ triggers.ts      # GAS trigger functions
โ”‚   โ””โ”€โ”€ utils/
โ”‚       โ””โ”€โ”€ helpers.ts   # Utility functions
โ”œโ”€โ”€ dist/                # Build output (individual files)
โ”‚   โ”œโ”€โ”€ main.js
โ”‚   โ”œโ”€โ”€ triggers.js
โ”‚   โ””โ”€โ”€ helpers.js
โ”œโ”€โ”€ vite.config.ts
โ””โ”€โ”€ package.json

Example Code

Input (TypeScript)

// src/main.ts
import { logMessage } from './utils/helpers'

function main() {
  logMessage('Hello, GAS!')
}

// src/triggers.ts
function onOpen() {
  main()
}

function onEdit(e: GoogleAppsScript.Events.SheetsOnEdit) {
  console.log('Cell edited:', e.range.getA1Notation())
}

Output (JavaScript)

// dist/main.js
function logMessage(message) {
  Logger.log(message);
}

function main() {
  logMessage('Hello, GAS!');
}

// dist/triggers.js
/* @preserve onOpen */ function onOpen() {
  main();
}

/* @preserve onEdit */ function onEdit(e) {
  Logger.log('Cell edited:', e.range.getA1Notation());
}

Protected GAS Functions

The plugin automatically protects these GAS special functions from minification:

  • onOpen() - Triggered when a spreadsheet/document is opened
  • onEdit(e) - Triggered when a spreadsheet is edited
  • onSelectionChange(e) - Triggered when selection changes
  • onFormSubmit(e) - Triggered when a form is submitted
  • doGet(e) - HTTP GET request handler
  • doPost(e) - HTTP POST request handler
  • onInstall(e) - Triggered when an add-on is installed

Scripts

{
  "scripts": {
    "build": "vite build",
    "dev": "vite build --watch",
    "deploy": "npm run build && clasp push"
  }
}

Requirements

  • Node.js 18.0.0 or higher
  • Vite 5.0.0 or higher

Development Requirements

This project follows strict development standards:

Code Quality Standards

  • Zero Warning Policy: No TypeScript warnings or linting warnings are tolerated
  • Type Safety: Strict TypeScript configuration with no any types
  • Test Coverage: Minimum 90% test coverage required (currently achieving 94.94%)
  • Error Handling: Comprehensive error handling with proper runtime type checking

File Naming Convention

  • camelCase: All source files use camelCase naming convention
  • Examples:
    • gasConfigProcessor.ts (not gas-config-processor.ts)
    • fileDetector.ts (not file-detector.ts)
    • viteConfig.ts (not vite-config.ts)

Testing Standards

  • All new features must include comprehensive tests
  • Tests must cover both success and error cases
  • Mock external dependencies appropriately
  • Maintain high test coverage (90%+ required)

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.