gas-build
raw JSON → 0.0.3 verified Fri May 01 auth: no javascript
ESBuild plugin and CLI (v0.0.3) for bundling modern TypeScript/JavaScript code into Google App Script (GAS). Combines ESBuild bundling with transformations required by GAS runtime (e.g., handling of `google.script.run`, `ScriptApp`). Peer dependency on `esbuild` ^0.24.2. Differentiator: no need for separate GAS-specific transpilation steps; single pass via ESBuild plugin. Actively maintained by Salsita.
Common errors
error Error: Build failed with 1 error: ... Could not resolve 'google.script.run' ↓
cause The plugin expects GAS-specific globals to be used as such; ESBuild does not resolve them.
fix
Add
google to the define option in ESBuild config (e.g., define: { 'google': '{}' }), or use the plugin's built-in handling. error TypeError: gasBuildPlugin is not a function ↓
cause Importing default export instead of named export.
fix
Use
import { gasBuildPlugin } from 'gas-build'. error Error: Cannot find module 'gas-build' ↓
cause Package not installed or node_modules not present.
fix
Run
npm install -D gas-build esbuild. Warnings
deprecated Options like `outdir` (instead of `outfile`) may not be supported; plugin expects a single output file. ↓
fix Always use `outfile` instead of `outdir` when using the plugin.
gotcha The plugin does not warn if `format` is missing. If set incorrectly, output may not work in GAS runtime. ↓
fix Set `format: 'esm'` or omit to default to 'iife' (GAS compatible). Avoid 'cjs'.
gotcha ESBuild must be installed as a separate peer dependency. The package does not include it. ↓
fix Run `npm install -D gas-build esbuild`.
breaking Version 0.0.3 may have breaking changes from earlier 0.0.x versions; no changelog provided. ↓
fix Pin to latest version and test build after update.
Install
npm install gas-build yarn add gas-build pnpm add gas-build Imports
- gasBuildPlugin wrong
import gasBuildPlugin from 'gas-build'correctimport { gasBuildPlugin } from 'gas-build' - gasBuildPlugin wrong
const gasBuildPlugin = require('gas-build').defaultcorrectconst { gasBuildPlugin } = require('gas-build') - CLI wrong
node ./node_modules/.bin/gas-build src/index.ts --outfile dist/bundle.jscorrectnpx gas-build src/index.ts --outfile dist/bundle.js
Quickstart
// build script: build.mjs
import { build } from 'esbuild';
import { gasBuildPlugin } from 'gas-build';
await build({
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'dist/bundle.js',
platform: 'node',
target: 'es2020',
format: 'esm',
plugins: [gasBuildPlugin()],
});
// Run with: node build.mjs