Skip to content

Instantly share code, notes, and snippets.

@uebayasi
Last active April 24, 2026 11:45
Show Gist options
  • Select an option

  • Save uebayasi/1b7560c76f08b33b64689e62a580f589 to your computer and use it in GitHub Desktop.

Select an option

Save uebayasi/1b7560c76f08b33b64689e62a580f589 to your computer and use it in GitHub Desktop.
Building Google App Script (GAS) with rslib
import { LibConfig, RslibConfig } from '@rslib/core'
// how to use this in rslib.config.ts:
// - `import { gasLib } from './rslib-gas.ts'
// - add a `lib` entry like: `lib: [gasLib('doPut')]`
// - put appsscript.json under public/; it's copied to dist/ as is
//
// how it works:
// - build & bundle .ts into dist/Code.js
// - export global names via `global`; see the first/last lines in Code.js
const UMD_NAME = 'GAS_APP'
function listNames(names: string[]): string {
return names
.map(
(name) =>
`function ${name}(...args) { return global["${UMD_NAME}"].${name}(...args); }`
)
.join('\n')
}
export function gasLib(names: string[]): LibConfig {
return {
format: 'umd',
umdName: UMD_NAME,
syntax: 'es2020',
bundle: true,
output: {
filename: {
js: 'Code.js',
},
},
banner: {
js: 'var global = this;',
},
footer: {
js: listNames(names),
},
}
}
export function gasConfig(names: string[]): RslibConfig {
return {
lib: [gasLib(names)],
output: {
// appsscript.json
copy: [{ from: 'public' }],
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment