{"id":12856,"library":"aws-sam-webpack-plugin","title":"AWS SAM Webpack Plugin","description":"The `aws-sam-webpack-plugin` is a Webpack plugin designed to integrate Webpack into the AWS Serverless Application Model (SAM) CLI build process. Its primary function is to replace the traditional `sam build` command, offering an alternative for developers working with Node.js runtimes. This plugin emerged to address two key limitations of the SAM CLI at the time: a lack of robust native TypeScript support and slow build times, particularly due to SAM CLI's tendency to run `npm pack` and `npm install` for each function. It facilitates faster builds, comprehensive TypeScript and Babel support via Webpack loaders, and can even auto-generate VS Code debugging configurations. The current stable version is 0.16.0. However, the project is explicitly in a maintenance-only state, as the author now recommends utilizing the AWS SAM CLI's built-in TypeScript support, which has since matured. While community PRs for new runtime support will be merged, active feature development has ceased. This plugin's historical significance lies in providing a more efficient, Webpack-driven build workflow for SAM applications, especially beneficial for TypeScript users, before official tooling caught up.","status":"maintenance","version":"0.16.0","language":"javascript","source_language":"en","source_url":"https://github.com/StackToolbox/aws-sam-webpack-plugin","tags":["javascript","webpack","aws","sam","typescript","babel"],"install":[{"cmd":"npm install aws-sam-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add aws-sam-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add aws-sam-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency as this is a Webpack plugin.","package":"webpack","optional":false},{"reason":"Needed to run Webpack commands.","package":"webpack-cli","optional":false},{"reason":"Required for TypeScript projects, often used with this plugin.","package":"typescript","optional":true},{"reason":"Webpack loader for TypeScript files, commonly used with this plugin.","package":"ts-loader","optional":true},{"reason":"Provides TypeScript definitions for AWS Lambda handler types.","package":"@types/aws-lambda","optional":true},{"reason":"Although often externalized in Lambda bundles, it's a common runtime dependency. If not externalized, it must be included.","package":"aws-sdk","optional":true}],"imports":[{"note":"The plugin is typically consumed as a default export in modern TypeScript/ESM projects. The CommonJS 'require' syntax is also shown in examples but less common for new ESM projects.","wrong":"const AwsSamPlugin = require('aws-sam-webpack-plugin');","symbol":"AwsSamPlugin","correct":"import AwsSamPlugin from 'aws-sam-webpack-plugin';"}],"quickstart":{"code":"npm install webpack webpack-cli typescript ts-loader aws-sam-webpack-plugin @types/aws-lambda rimraf --save-dev\n# OR\nyarn add webpack webpack-cli typescript ts-loader aws-sam-webpack-plugin @types/aws-lambda rimraf -D\n\n# Production dependencies (often externalized for Lambda)\nnpm install aws-sdk --save\n# OR\nyarn add aws-sdk --save\n\n// webpack.config.js\nconst path = require(\"path\");\nconst AwsSamPlugin = require(\"aws-sam-webpack-plugin\");\n\nconst awsSamPlugin = new AwsSamPlugin();\n\nmodule.exports = {\n  // Loads the entry object from the AWS::Serverless::Function resources in your\n  // SAM config. Setting this to a function will reload your SAM config on rebuild.\n  entry: () => awsSamPlugin.entry(),\n\n  // Write the output to the .aws-sam/build folder\n  output: {\n    filename: (chunkData) => awsSamPlugin.filename(chunkData),\n    libraryTarget: \"commonjs2\",\n    path: path.resolve(\".\"),\n  },\n\n  // Create source maps\n  devtool: \"source-map\",\n\n  // Resolve .ts and .js extensions\n  resolve: {\n    extensions: [\".ts\", \".js\"],\n  },\n\n  // Target node for Lambda environment\n  target: \"node\",\n\n  // Exclude aws-sdk from bundle by default for smaller package size\n  externals: process.env.NODE_ENV === \"development\" ? [] : [\"aws-sdk\"],\n\n  // Set the webpack mode\n  mode: process.env.NODE_ENV || \"production\",\n\n  // Add the TypeScript loader\n  module: {\n    rules: [{ test: /\\.tsx?$/, loader: \"ts-loader\" }],\n  },\n\n  // Add the AWS SAM Webpack Plugin\n  plugins: [\n    awsSamPlugin\n  ]\n};","lang":"typescript","description":"This quickstart demonstrates how to install the plugin and configure a `webpack.config.js` file for a typical AWS SAM project using TypeScript. It includes setting up dynamic entry points, output paths, TypeScript loader, and handling `aws-sdk` externals for Lambda."},"warnings":[{"fix":"Evaluate migrating existing projects or starting new projects with the official AWS SAM CLI's TypeScript capabilities to leverage active development and support.","message":"The author now recommends using the native AWS SAM CLI's built-in TypeScript support. This plugin is primarily in maintenance mode with limited updates, only accepting PRs for new runtime support.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Ensure all Lambda functions in your SAM template use Node.js 10.x runtime or newer. If you must use Node.js 8.10, pin the plugin version to `<0.6.0`.","message":"Node.js 8.10 runtime support was removed.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Verify that all Lambda handler paths specified in your `template.yaml` (or inferred) correctly point to existing files. Webpack's resolution extensions (`resolve.extensions`) are now used for checking existence.","message":"The build process will now fail if the specified handler file for a Lambda function does not exist.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"If you are on `v0.5.0` and experienced compatibility issues, immediately upgrade to `v0.5.1` or a newer version to resolve the bug.","message":"Version 0.5.0 introduced a bug that broke backwards compatibility with v0.4.0 projects.","severity":"breaking","affected_versions":"0.5.0"},{"fix":"Consider refactoring `InlineCode` to use `CodeUri` pointing to a file or directory for better maintainability and to avoid console warnings, or acknowledge the warning if `InlineCode` is explicitly desired.","message":"Using `InlineCode` in your SAM template, rather than a `CodeUri`, will generate a warning message on the console.","severity":"gotcha","affected_versions":">=0.4.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Verify that the handler path in your `template.yaml` is correct and the file exists. Ensure your `webpack.config.js` `resolve.extensions` array includes the correct file extension (e.g., `.ts`, `.js`) for your handler files.","cause":"The handler file specified for a Lambda function in your SAM template (or derived) cannot be found by Webpack's module resolution.","error":"Error: Webpack can't resolve '[HANDLER_PATH]' in '[PROJECT_ROOT]'"},{"fix":"Modify your `webpack.config.js` to set the entry point as a function: `entry: () => awsSamPlugin.entry()`. This ensures the SAM template is reloaded and parsed on every Webpack rebuild, reflecting any changes.","cause":"The `entry` option in your `webpack.config.js` is set to `awsSamPlugin.entry()` directly instead of a function that re-evaluates the entry points on each build.","error":"Changes in SAM template (e.g., new functions, changed runtimes) are not reflected after Webpack rebuilds."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null}