Gas Build
An ESBuild plugin and simplified CLI for bundling of Google App Script projects from
a modern TypeScript / JavaScript codebase.
Installation
npm install -D gas-build esbuild
This installs both the plugin and the CLI. Note that esbuild
is declared as a peer
dependency and must be installed separately.
Usage
CLI
This is a preferred method for simple projects with a single entry point.
To build your project, call the gas-build
command with the entry point file and the output file:
gas-build src/index.ts --outfile dist/bundle.js
Note that you might have to wrap the command in a package.json
script so that the gas-build
is properly recognized:
{
"scripts": {
"build": "gas-build src/index.ts --outfile dist/bundle.js"
}
}
Watch mode
The CLI also supports simple watch mode. Enable it by passing the --watch
flag:
gas-build src/index.ts --outfile dist/bundle.js --watch
Plugin
When the CLI is not sufficient, you can use the plugin directly in your build script.
Define a custom build script, using the esbuild
API, and include the gasBuildPlugin
.
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 the build script using node
:
node build.mjs