{"id":20047,"library":"gas-webpack-plugin","title":"gas-webpack-plugin","description":"Webpack plugin for Google Apps Script that transforms module exports into top-level function declarations compatible with google.script.run. Current version 2.6.0, maintained regularly. It bridges the gap between webpack's module system and GAS's requirement that callable functions be globally declared. Supports both CommonJS and ES module syntax, works with webpack 4 and 5. Key differentiator: automates generation of GAS-compatible wrapper code from standard webpack bundles, avoiding manual function declarations.","status":"active","version":"2.6.0","language":"javascript","source_language":"en","source_url":"https://github.com/fossamagna/gas-webpack-plugin","tags":["javascript","typescript"],"install":[{"cmd":"npm install gas-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add gas-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add gas-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS require is standard; ES module import may work with bundler settings but not officially supported.","wrong":"import GasPlugin from 'gas-webpack-plugin';","symbol":"GasPlugin","correct":"const GasPlugin = require('gas-webpack-plugin');"},{"note":"GasPlugin is the default export, not a named export.","wrong":"const { GasPlugin } = require('gas-webpack-plugin');","symbol":"GasPlugin","correct":"const GasPlugin = require('gas-webpack-plugin');"}],"quickstart":{"code":"// webpack.config.js\nconst GasPlugin = require('gas-webpack-plugin');\nconst path = require('path');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'Code.gs'\n  },\n  plugins: [\n    new GasPlugin()\n  ]\n};\n\n// src/index.js\nconst myFunc = require('./myFunc');\nglobal.myFunc = myFunc;\n\n// src/myFunc.js\nmodule.exports = function(message) {\n  return message;\n};","lang":"javascript","description":"Sets up webpack with gas-webpack-plugin to bundle code for Google Apps Script, converting global assignments to top-level function declarations."},"warnings":[{"fix":"Ensure assignments like global.myFunc = myFunc are at the top level of entry file, not inside conditionals or callbacks.","message":"Functions assigned to global must be top-level; nested assignments may not be detected.","severity":"gotcha","affected_versions":"all"},{"fix":"Use output.filename option to customize; or update to >=2.5.0 for better behavior.","message":"Plugin outputs Code.gs; ensure no file naming conflicts if multiple outputs.","severity":"gotcha","affected_versions":"<2.5.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Confirm gas-webpack-plugin is correctly installed and webpack config includes the plugin. Use global.xxx = xxx assignment at top-level of entry module.","cause":"Top-level function not generated because assignment was not detected.","error":"Global function not defined in Google Apps Script"},{"fix":"Ensure the function is assigned to global object in the entry point: global.myFunction = myFunction;","cause":"The function is not exposed globally due to improper assignment.","error":"Uncaught ReferenceError: ... is not defined when calling from client side"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}