1.1.13 • Published 2 months ago

rollup-plugin-google-apps-script v1.1.13

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

rollup-plugin-google-apps-script

npm version CI/CD codecov CodeFactor GitHub

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

  1. NPM

    npm install -D rollup-plugin-google-apps-script
  2. 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 | | ------------------- | :---------------: | :-------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | comment | {boolean} | false | If true then generate a top level function declaration statement with comment. | | 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. | | verbose | {boolean} | false | If true then output details of processing to the console. |

Example

Node

  1. 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",
    });
  2. Run build script

    ts-node build.ts

vite

  1. 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"),
        },
      },
    });
  2. Add build script in package.json

    // package.json
    {
      ...
      "scripts": {
        ...
        "build": "vite build",
        ...
      },
      ...
    }
  3. Run the build command

    npm run build

Note

  • Some rollup options are overridden in plugins.

    OptionValue
    output.formatumd
  • When use vite, following configration is required.

    OptionValueRemarks
    build.minifyfalseDisable minify because the function name defined in script is changed.
1.1.13

2 months ago

1.1.12

7 months ago

1.1.11

9 months ago

1.1.10

10 months ago

1.1.9

10 months ago

1.1.8

10 months ago

1.1.7

10 months ago

1.1.6

11 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago