This plugin allows you to execute functions exported within Google Apps Script (GAS) environment.
npm install --save-dev esbuild-plugin-gas-generator
How to use the plugin in your build script:
build.js
const esbuild = require("esbuild");
const GasPlugin = require("esbuild-plugin-gas-generator");
esbuild
.build({
entryPoints: ["src/index.js"],
// Must be set to true
bundle: true,
// Must be set to 'iife'
format: "iife",
// Automatically set true
metafile: true,
// Must be followed
outfile: "dist/bundle.js",
plugins: [GasPlugin({
appsscript: "appsscript.json",
// Or you can specify the options directly
appsscript: {
timeZone: "Asia/Tokyo",
dependencies: {},
exceptionLogging: "STACKDRIVER",
runtimeVersion: "V8"
}
})],
})
.catch((e) => {
console.error(e);
process.exit(1);
});
src/index.js
export function hello() {
console.log("Hello, World!");
}
You can pass an object with options to the plugin:
appsscript
(string | object): The path to theappsscript.json
file or an object with the options directly.excludePlugins
(string[]): This plugin performs the build process twice. If other plugins also perform the build process twice, the build will not complete, so please exclude them.
const esbuild = require("esbuild");
const GasPlugin = require("esbuild-plugin-gas-generator");
esbuild
.build({
entryPoints: ["src/index.js", "src/main.js"],
bundle: true,
format: "esm",
outdir: "dist",
plugins: [
GasPlugin({
excludePlugins: ["esbuild-plugin-examples"]
appsscript: "appsscript.json",
}),
],
})
.catch((e) => {
console.error(e);
process.exit(1);
});
MIT