npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-google-apps-script

v2.0.1

Published

Rollup plugin for Google Apps Script.

Downloads

418

Readme

rollup-plugin-google-apps-script

npm version CI 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 | | ------------------- | :---------------: | :-------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 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

  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.

    | 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. |