This demonstrates how to use Svelte with Google Apps Script using Clasp for seamless deployment. This demonstrates how to use Svelte with Google Apps Script.
- Node.js installed on your machine
- A Google account
- Enable the Google Apps Script API at https://script.google.com/home/usersettings
npm installto install dependencies.npm run devto start the development server.- Open
http://localhost:5173in your browser to see the app. - Edit the Svelte components in the
srcfolder. The app will reload automatically
npm run build- Build the Svelte applicationnpm run preview- Preview the production build locallynpm run check- Run TypeScript and Svelte checks
Enable the Google Apps Script API: https://script.google.com/home/usersettings
Login to your Google account:
npm run clasp:loginThis will open a browser window for authentication.
Option A: Create a new project
npm run clasp:createThis creates a new Google Apps Script project and generates a .clasp.json file with your project credentials.
Option B: Connect to an existing project
If you already have a Google Apps Script project, create a .clasp.json file in the root directory:
{
"scriptId": "YOUR_SCRIPT_ID_HERE",
"rootDir": "gas"
}Replace YOUR_SCRIPT_ID_HERE with your script ID (found in Project Settings in the Apps Script editor).
Build your Svelte app and push to Google Apps Script:
npm run clasp:pushThis command builds the project and pushes all files to your Apps Script project.
-
Open your Apps Script project:
npm run clasp:open
-
In the Apps Script editor, click Deploy > New deployment
-
Select type Web app
-
Configure access settings as needed
-
Click Deploy
npm run clasp:login- Authenticate with Googlenpm run clasp:logout- Logout from Googlenpm run clasp:create- Create a new Apps Script projectnpm run clasp:push- Push code to Apps Scriptnpm run clasp:open- Open the Apps Script project in browsernpm run clasp:deploy- Create a new deploymentnpm run clasp:deployments- List all deploymentsnpm run deploy- Build and push to Apps Script (recommended)
.
├── gas/ # Google Apps Script files
│ ├── appsscript.json # Apps Script manifest
│ ├── Code.js # Server-side Apps Script code
│ ├── Index.html # Main HTML template
│ ├── Javascript.html # Generated from build (auto-generated)
│ └── Stylesheet.html # Generated from build (auto-generated)
├── src/ # Svelte source files
├── .claspignore # Files to ignore when pushing
└── .clasp.json # Clasp configuration (gitignored)
- Add your Svelte components in the
src/libfolder. - Import and use them in
src/App.svelte. - If you need to call Google Apps Script functions from Svelte, use the google.script.run API. See
testInvokationFromClientexample in Apps.svelte