With support for React v18 and React Fast Refresh
π This is your boilerplate project for developing React apps inside Google Sheets, Docs, Forms and Slides projects. It's perfect for personal projects and for publishing complex add-ons in the Google Workspace Marketplace.
This build env deploys to sdss-gas project in the browser based apps script console under alexander.liukkonen@gmail.com
After the release version is ready and tested, it is moved over to Simulate apps script project with a simple copy-paste.
The deployments and production versioning is then handled under the separate Simulate project directory.
Guide from current docs: https://developers.google.com/workspace/add-ons/how-tos/update-published-add-on
export NODE_OPTIONS="--max-old-space-size=8192"
Google Apps Script is Google's Javascript-based development platform for building applications and add-ons for Google Sheets, Docs, Forms and other Google Apps.
You can add custom user interfaces inside dialog windows, but the platform is designed for simple HTML pages built with templates and jQuery.
However, using this repo, it's easy to run React apps inside these dialogs, and build everything from small projects to advanced add-ons that can be published on the G Suite Marketplace.
This repo is a boilerplate project that uses React and the same development tools that you use for building traditional websites, all inside Google Apps Script projects.
See below how to get started!
These instructions will get you set up with a copy of the React project code on your local machine. It will also get you logged in to clasp
so you can manage script projects from the command line.
See deploy for notes on how to deploy the project and see it live in a Google Spreadsheet.
Make sure you're running at least Node.js v14 and npm
v6.
You'll need to enable the Google Apps Script API. You can do that by visiting script.google.com/home/usersettings.
To use live reload while developing, you'll need to serve your files locally using HTTPS. See local development below for how to set up your local environment.
1. First, let's clone the repo and install the dependencies.
git clone https://github.com/enuchi/React-Google-Apps-Script.git
cd React-Google-Apps-Script
npm install
2. Next, we'll need to log in to clasp, which lets us manage our Google Apps Script projects locally.
npm run login
3. Now let's run the setup script to create a New spreadsheet and script project from the command line.
npm run setup
Alternatively, you can use an existing Google Spreadsheet and Script file instead of creating a new one.
Next, let's deploy the app so we can see it live in Google Spreadsheets.
Run the deploy command. You may be prompted to update your manifest file. Type 'yes'.
npm run deploy
The deploy command will build all necessary files using production settings, including all server code (Google Apps Script code), client code (React bundle), and config files. All bundled files will be outputted to the dist/
folder, then pushed to the Google Apps Script project.
Now open Google Sheets and navigate to your new spreadsheet (e.g. the file "My React Project"). You can also run npm run open
. Make sure to refresh the page if you already had it open. You will now see a new menu item appear containing your app!
We can develop our client-side React apps locally, and see our changes directly inside our Google Spreadsheet dialog window.
There are two steps to getting started: installing a certificate (first time only), and running the start command.
Generating a certificate for local development
Install the mkcert package:
# mac:
brew install mkcert
# windows:
choco install mkcert
Then run the mkcert install script:
mkcert -install
Create the certs in your repo:
npm run setup:https
Now you're ready to start:
npm run start
The start command will create and deploy a development build, and serve your local files.
After running the start command, navigate to your spreadsheet and open one of the menu items. It should now be serving your local files. When you make and save changes to your React app, your app will reload instantly within the Google Spreadsheet, and have access to any server-side functions!
Support for Fast Refresh now means that only modified components are refreshed when files are changed, and state is not lost.
React DevTools is a tool that lets you inspect the React component hierarchies during development.