serverless-plugin-webpack

raw JSON →
1.5.1 verified Sat Apr 25 auth: no javascript abandoned

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.

error Error: Cannot find module 'webpack'
cause Webpack is a peer dependency and must be installed separately.
fix
npm install webpack@3 --save-dev
error Error: Cannot find module 'serverless-plugin-webpack'
cause The plugin is not installed or not listed as a plugin in serverless.yml correctly.
fix
npm install serverless-plugin-webpack --save-dev and ensure it's in serverless.yml plugins array.
error Error: The serverless instance is not supported
cause Serverless version is below 1.18.0 (as of v1.3.0).
fix
Upgrade Serverless to >=1.18.0.
error TypeError: Cannot read property 'length' of undefined
cause Webpack stats output may be malformed when running in series (bug in v1.5.0).
fix
Update to v1.5.1 which fixes this bug.
gotcha Plugin uses serverless service handler references directly; custom webpack configs must not define entry/output as they are set by the plugin.
fix Do not specify entry or output in your webpack.config.js; the plugin will override them.
deprecated Only supports webpack 2.x or 3.x. Webpack 4 and 5 are not supported.
fix Upgrade to serverless-webpack (elastic-coders) which supports webpack 4+ and is actively maintained.
gotcha Individual function packaging may cause issues if functions share large dependencies; tree-shaking optimization can be unexpected if code has side effects.
fix Ensure ES6 modules are used and configure sideEffects in package.json to avoid dead code elimination failures.
breaking Dropped support for Serverless < 1.18.0 in v1.3.0.
fix Upgrade Serverless to v1.18.0 or later, or use an older version of the plugin.
gotcha Plugin automatically adds '**' as an exclude at service level; if you have custom excludes they will be merged, but unexpected exclusions may occur.
fix Review the generated .serverless directory to ensure correct files are included.
npm install serverless-plugin-webpack
yarn add serverless-plugin-webpack
pnpm add serverless-plugin-webpack

Shows minimal setup: install plugin and webpack 3, configure serverless.yml, create webpack.config.js, and deploy.

// 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