vite-plugin-gas-hoist
v0.1.2
Published
A Vite plugin that hoists entry point exports to the global scope for Google Apps Script
Maintainers
Readme
vite-plugin-gas-hoist
A Vite plugin that hoists entry point exports to the global scope for Google Apps Script (GAS).
Try it
Edit and build in your browser — no setup required. Once the build finishes, open dist/app.js to see the hoisted output.
Why?
GAS can only execute functions in the global scope, but Vite bundles all code inside an IIFE. This plugin automatically wraps entry point exports as global functions, bridging the gap.
// Before build (entry point)
export const sayHello = (name) => `Hello, ${name}!`;
// After build (plugin adds this)
function sayHello(...args) { return lib_.sayHello(...args) }Install
npm install -D vite-plugin-gas-hoistUsage
// vite.config.js
import { defineConfig } from 'vite';
import { vitePluginGasHoist } from 'vite-plugin-gas-hoist';
export default defineConfig({
plugins: [vitePluginGasHoist()],
build: {
lib: {
entry: 'src/main.js',
formats: ['iife'],
name: 'lib_',
fileName: (_, entryName) => `${entryName}.js`,
},
},
});Exported functions are hoisted to the global scope via the variable name specified in build.lib.name (e.g. lib_).
Requirements
build.lib.formatsmust include'iife'- Entry point must have at least one
export
