rollup-plugin-google-apps-script

raw JSON →
2.0.2 verified Mon Apr 27 auth: no javascript

Rollup plugin for Google Apps Script that generates top-level function declarations from global object assignments, enabling local development with modern bundlers and deployment via clasp. Current stable version 2.0.2, with support for Rollup ^3.25.0 || ^4.0.0 and Vite ^4.4.9. Maintained by mato533, inspired by gas-webpack-plugin. Releases are occasional; latest includes dependency updates and gas-entry-generator options. Key differentiators: works with both Rollup and Vite, generates GAS-compatible bundle structure, supports TypeScript out of the box.

error Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'rollup-plugin-google-apps-script'
cause CommonJS require() used instead of ESM import.
fix
Use import gasPlugin from 'rollup-plugin-google-apps-script'
error TypeError: gasPlugin is not a function
cause Named import used instead of default import.
fix
Use import gasPlugin from 'rollup-plugin-google-apps-script' (not import { gasPlugin })
error You assigned to global but no top-level function was generated
cause Function not assigned as global.property, or file not included in the include pattern.
fix
Ensure assignment is like global.myFunc = () => {} and include pattern covers the file.
breaking Major version v2.0.0 introduces gasEntryOptions and restructures option object; old top-level options like comment are deprecated.
fix Move comment option under gasEntryOptions.comment; see migration guide.
deprecated The top-level 'comment' option is deprecated in v2.0.0.
fix Use gasEntryOptions.comment instead.
gotcha Plugin generates top-level function declarations only for assignments to a property of the 'global' object (e.g., global.myFunc = ...). Other patterns are ignored.
fix Ensure all GAS-entry functions are assigned as global.property = ...
gotcha Requires import using ESM syntax; CommonJS require() will throw an error (module not found).
fix Use import gasPlugin from 'rollup-plugin-google-apps-script'
gotcha When using Vite, ensure Vite version ^4.4.9 is used; older versions may have compatibility issues.
fix Upgrade Vite to ^4.4.9 or later.
npm install rollup-plugin-google-apps-script
yarn add rollup-plugin-google-apps-script
pnpm add rollup-plugin-google-apps-script

Configures Vite with the gas plugin, setting input file, output directory, and GAS-specific options like manifest copy and entry generator settings.

import gasPlugin from 'rollup-plugin-google-apps-script';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    gasPlugin({
      include: ['**/*.js'],
      moduleHeaderComment: true,
      manifest: {
        copy: true,
        srcDir: 'src',
      },
      gasEntryOptions: {
        comment: true,
        autoGlobalExports: false,
        exportsIdentifierName: 'exports',
        globalIdentifierName: 'global',
      },
      verbose: true,
    }),
  ],
  build: {
    outDir: 'dist',
    rollupOptions: {
      input: 'src/main.js',
      output: {
        format: 'esm',
        entryFileNames: 'bundle.js',
      },
    },
  },
});