Serverless Plugin Webpack
Compared to other webpack/optimization plugins, this plugin has the following features/advantages:
- Zero configuration
sls deploy function
- Functions are packaged individually, resulting in Lambda deployment packages (zip) containing only the code needed to run the function (no bloat)
- Uses an array of webpack configurations instead of one webpack configuration with multiple entry points, resulting in better tree-shaking because dependencies are isolated (see Tree shaking).
This plugin is partially based on Serverless Webpack.
npm install serverless-plugin-webpack --save-dev
Add the plugin to your
Package exclude / include
The plugin will add
'**' as an
include at the function level. Original includes and excludes specified in your
serverless.yml are preserved.
By default the plugin will look for a
webpack.config.js in the service root. You can specify a custom config file in your
custom:webpack:config: ./path/to/config/file.jsseries: true # run Webpack in series, useful for large projects. Defaults to false.
output objects are set by the plugin.
Example of webpack config:
moduleexports =// entry: set by the plugin// output: set by the plugintarget: 'node'externals:/aws-sdk/ // Available on AWS Lambdamodule:rules:test: /\.js$/exclude: /node_modules/loader: 'babel-loader'query:presets:'env'target: node: '6.10' // Node version on AWS LambdauseBuiltIns: truemodules: falseloose: true'stage-0';