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.
npm install to install dependencies.npm run dev to start the development server.http://localhost:5173 in your browser to see the app.src folder. The app will reload automaticallynpm run build - Build the Svelte applicationnpm run preview - Preview the production build locallynpm run check - Run TypeScript and Svelte checksEnable the Google Apps Script API: https://script.google.com/home/usersettings
Login to your Google account:
npm run clasp:login
This will open a browser window for authentication.
Option A: Create a new project
npm run clasp:create
This 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:push
This 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)
src/lib folder.src/App.svelte.testInvokationFromClient example in Apps.svelte