labnol/apps-script-starter
关于
在 Visual Studio Code 中搭建本地开发环境,并使用 Google Apps Script 构建 Google Workspace 插件。
其他项目实测星标增长
- 24小时
- 0
- 7天
- +1
- 15天
- +1
- 1个月
- 0
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Google Apps Script Starter Kit
Write Google Apps Script in VS Code with modern JavaScript, ES modules, tests and linting. Vite bundles your code into one file, and clasp uploads it to your Apps Script project. Digital Inspiration uses this kit to build Mail Merge, Form Notifications and Document Studio.

Quick start
You need Node.js 20.19 or later, and the Apps Script API turned on in your Apps Script settings. clasp cannot create or push projects without it.
npx degit labnol/apps-script-starter my-project
cd my-project
npm install
npx clasp login
npx clasp create --type sheets --title "My Project" --rootDir dist
npm run deploy
npx clasp open-script
clasp create makes a new Google Sheet with a bound script and writes .clasp.json. Use --type standalone for a script without a file, or npx clasp clone <scriptId> --rootDir dist to use a project you already have.
How it works
Apps Script can only call top-level global functions. Vite bundles src/ into dist/code.js, and a small plugin (vite-plugins/gas-expose.js) adds a global function for each export of src/index.js. If a function is not exported there, Apps Script cannot call it.
// src/index.js
import { getGmailAliases } from './server/gmail.js';
import { doGet } from './server/webapp.js';
// doGet serves the web app. getGmailAliases can be called from the HTML with google.script.run.
// Add triggers such as onOpen or onEdit to this list the same way.
export { doGet, getGmailAliases };
Some files are copied into dist/ as they are, without bundling:
functions/*.js: custom functions for Google Sheets, such as=DOUBLE(A1). Sheets needs them as plain global functions with a JSDoc@customfunctiontag.src/html/*.html: HTML for web apps, sidebars and dialogs. Load them by file name, for exampleHtmlService.createHtmlOutputFromFile('index').appsscript.json: the project manifest. It also loads Apps Script libraries such as OAuth2.
Commands
| Command | What it does |
|---|---|
npm run dev |
Rebuilds dist/ when a file changes. It does not upload. |
npm run deploy |
Builds and pushes dist/ to Apps Script. |
npm test |
Runs the Node.js tests (*.test.js, next to the code they test). |
npm run lint |
Checks the code with ESLint. |
npm run format |
Formats the code with Prettier. |
npx clasp open-script |
Opens the project in the Apps Script editor. |
npx clasp open-logs |
Opens the execution logs. |
npx clasp deploy |
Creates a versioned deployment, for example to publish a web app. |
To upload on every save, run npm run dev in one terminal and npx clasp push --watch in another.
Tests run in Node, where Apps Script services such as SpreadsheetApp do not exist. Keep the logic in plain functions you can test, as http.test.js does, or mock the services.
Project layout
src/index.js Exports that become global functions
src/server/ Server-side code
src/html/ HTML files, copied as-is
functions/ Sheets custom functions, copied as-is
appsscript.json Manifest: scopes, services, libraries, web app settings
vite.config.js Build settings (output folder, minify, copied files)
eslint.config.js Lint rules from @labnol/js-config, plus local overrides
Edit the manifest first
The sample appsscript.json is an example. Change it before you deploy:
oauthScopes: list every scope your code needs. When this field is set, Apps Script grants only these scopes. See scopes.md for the full list.timeZone: set your own time zone. The sample usesAsia/Calcutta.webapp: the sample lets anyone open the web app, and it runs as the user who opens it. Changeaccessif you don't want that.enabledAdvancedServicesandlibraries: remove the ones you don't use. The sample turns on the advanced Gmail and Drive services, and adds the OAuth1 and OAuth2 libraries.
Linting and formatting
ESLint and Prettier settings come from @labnol/js-config. Its Apps Script preset already knows globals such as SpreadsheetApp and google.script.run. Install the VS Code extension pack to see lint errors and format on save.
License
MIT. See LICENSE. Built by Amit Agarwal at Digital Inspiration. The video tutorial is from 2019 and shows an older webpack version of this kit.
探索相关项目
加载中…