Skip to content

Add support for wrapping individually packaged lambda functions via serverless-webpack #64

@lucasklaassen

Description

@lucasklaassen

Description

serverless-webpack offers the ability to utilize webpacks Tree-Shaking and indiviually package lambda functions that only contain the modules and dependencies that they consume. This allows you to develop multiple lambda functions within the same repo or project and not bundle all of the dependencies for the entire project into every function. (just the ones that each function needs) Unfortunately it appears that the serverless-plugin-iopipe does not support this. Instead of wrapping each individual lambda function with IOPipe, it bundles everything into one file and wraps the functions within that one big file.

Application and library versions

  • Serverless Framework: 1.26.1
  • @iopipe/iopipe: 1.6.0
  • serverless-plugin-iopipe: 1.1.0
  • serverless-webpack: 5.1.0
  • webpack: 4.1.1

serverless.yml

plugins:
  - serverless-plugin-iopipe
  - serverless-dynamodb-local
  - serverless-offline
  - serverless-webpack
  - serverless-secrets-plugin
  - serverless-vpc-discovery
  - serverless-sqs-alarms-plugin

custom:
...
  webpack:
    package:
      individually: true

webpack.config.js

const nodeExternals = require('webpack-node-externals');
const path = require('path');
const slsw = require('serverless-webpack');
const webpack = require('webpack');

module.exports = {
  mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
  devtool: 'source-map',
  entry: slsw.lib.entries,
  target: 'node',
  externals: [nodeExternals()],
  output: {
    libraryTarget: 'commonjs',
    path: path.resolve(__dirname, '.webpack'),
    filename: '[name].js'
  },
  plugins: [
    new webpack.IgnorePlugin(/\.(md|yml.encrypted|sh|vm)$/)
  ],
  module: {
    rules: [{
      test: /\.jsx?$/,
      exclude: /node_modules/,
      use: [{
        loader: 'babel-loader'
      }]
    },
    {
      test: /\.json$/,
      use: [{
        loader: 'json-loader'
      }]
    },
    {
      test: /\.yml$/,
      use: [{
        loader: 'yml'
      }]
    }
    ]
  }
};

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions