serverless-plugin-webpack
raw JSON →A Serverless Framework plugin that automatically bundles each Lambda function individually using Webpack. Version 1.5.1 is the latest stable release (last updated in 2018). It supports webpack 2.x and 3.x (peer dependency), and was designed to work with Serverless v1.18+. Key differentiators: zero configuration required, functions are packaged individually for minimal deployment size, uses an array of Webpack configs (one per function) for better tree-shaking, and supports sls package/deploy/deploy function commands. This plugin is distinct from the more popular serverless-webpack plugin (by elastic-coders) and is now essentially superseded by that and newer tools like serverless-bundle. No longer actively maintained; users should migrate to serverless-webpack or serverless-esbuild.
Common errors
error Error: Cannot find module 'webpack' ↓
error Error: Cannot find module 'serverless-plugin-webpack' ↓
error Error: The serverless instance is not supported ↓
error TypeError: Cannot read property 'length' of undefined ↓
Warnings
gotcha Plugin uses serverless service handler references directly; custom webpack configs must not define entry/output as they are set by the plugin. ↓
deprecated Only supports webpack 2.x or 3.x. Webpack 4 and 5 are not supported. ↓
gotcha Individual function packaging may cause issues if functions share large dependencies; tree-shaking optimization can be unexpected if code has side effects. ↓
breaking Dropped support for Serverless < 1.18.0 in v1.3.0. ↓
gotcha Plugin automatically adds '**' as an exclude at service level; if you have custom excludes they will be merged, but unexpected exclusions may occur. ↓
Install
npm install serverless-plugin-webpack yarn add serverless-plugin-webpack pnpm add serverless-plugin-webpack Imports
- serverless-plugin-webpack wrong
// Using as an npm import in code (not applicable) const plugin = require('serverless-plugin-webpack'); // This is a Serverless plugin, not a code librarycorrect// Add to serverless.yml plugins array plugins: - serverless-plugin-webpack
Quickstart
// Install
npm install serverless-plugin-webpack webpack@3 --save-dev
// serverless.yml
service: my-service
plugins:
- serverless-plugin-webpack
provider:
name: aws
runtime: nodejs8.10
functions:
hello:
handler: handler.hello
// webpack.config.js
module.exports = {
target: 'node',
externals: [/aws-sdk/],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: [
['env', { target: { node: '8.10' }, useBuiltIns: true, modules: false, loose: true }],
'stage-0'
]
}
}
]
}
};
// Deploy
sls deploy