rollup-plugin-google-apps-script
v2.0.1
Published
Rollup plugin for Google Apps Script.
Downloads
504
Maintainers
Readme
rollup-plugin-google-apps-script
About
Rollup plugin for Google Apps Script. This plugin supports local development of applications that run on Google Apps Script. Files bundled using this plugin can be deployed to Google Apps Script using clasp.
Support build using Vite and Rollup.
This is inspired by gas-webpack-plugin.
Detail
Google Apps Script requires the entry point to be a top-level function declaration in order to be called from google.script.run
or some triggers. This plugin generates top-level function declaration statements when it encounters a global
object in a function assignment expression.
Sample of the source code
// main.js
// The plugin will nothing to generate for this function.
const sayHello = (target) => {
console.log(`Hello ${target}!!`);
};
// The plugin will generate a top-level function declaration for this function.
global.greet = () => {
sayHello("world");
};
Installation
NPM
npm install -D rollup-plugin-google-apps-script
Yarn
yarn add -D rollup-plugin-google-apps-script
Usage
Options
You can pass a object of configuration options to rollup-plugin-gas. Allowed values are as follows
| Name | Type | Default | Description |
| ------------------- | :---------------: | :-------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| include | {Array<string>}
| [**/*]
| Array of path patterns to detect functions to generate top level function definitions. accept glob pattern. |
| moduleHeaderComment | {boolean}
| false
| If true
, Print a comment of the module filename to the bandle file. |
| manifest.copy | {boolean}
| false
| if ture, copy the manifest file (appsscript.json
) to output directory from manifest.srcDir
. |
| manifest.srcDir | {string}
| process.cwd()
| Set relative path from the project root to the directory where the manifest file (appsscript.json
) is located, if you create the file at other than project root. |
| gasEntryOptions.comment | {boolean}
| false
| If true
then generate a top level function declaration statement with comment. |
| gasEntryOptions.autoGlobalExports | {boolean}
| false
| Options for gas-entry-generator
|
| gasEntryOptions.exportsIdentifierName | {string}
| exports
| Options for gas-entry-generator
|
| gasEntryOptions.globalIdentifierName | {string}
| global
| Options for gas-entry-generator
|
| verbose | {boolean}
| false
| If true
then output details of processing to the console. |
Example
Node
Create build script
// build.ts import path from "path"; import { fileURLToPath } from "url"; import { rollup } from "rollup"; import rollupPluginGas from "rollup-plugin-google-apps-script"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const entryPath = path.resolve(__dirname, "./code.js"); const distPath = path.resolve(__dirname, "./dist"); const bundle = await rollup({ input: entryPath, plugins: [rollupPluginGas()], }); await bundle.write({ dir: distPath, entryFileNames: "[name].js", });
Run build script
ts-node build.ts
vite
Create configration file for vite
// vite.config.ts import { defineConfig } from "vite"; import typescript from "@rollup/plugin-typescript"; import rollupPluginGas from "rollup-plugin-google-apps-script"; import path from "path"; export default defineConfig({ plugins: [typescript(), rollupPluginGas()], build: { rollupOptions: { input: "./src/main.ts", output: { dir: "./dist", entryFileNames: "[name].js", }, }, minify: false, // This option is requred. }, resolve: { alias: { "@": path.resolve(__dirname, "./src"), }, }, });
Add build script in package.json
// package.json { ... "scripts": { ... "build": "vite build", ... }, ... }
Run the build command
npm run build
Note
Some rollup options are overridden in plugins.
| Option | Value | | :-----------: | :---: | | output.format |
umd
|When use vite, following configration is required.
| Option | Value | Remarks | | :----------: | :-----: | ---------------------------------------------------------------------- | | build.minify |
false
| Disable minify because the function name defined in script is changed. |