Last active
April 24, 2026 11:45
-
-
Save uebayasi/1b7560c76f08b33b64689e62a580f589 to your computer and use it in GitHub Desktop.
Building Google App Script (GAS) with rslib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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