serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack
MIT License
1.72k stars 415 forks source link

Use webpack context config property as working directory for finding the handler functions #324

Open BrettStrongEH opened 6 years ago

BrettStrongEH commented 6 years ago

This is a Feature Proposal ...

Description

Currently the plugin does not take into account the working directory configured by webpack's "context" property value (i.e. in the webpack.config.js file), when searching for the serverless.yml handler functions (i.e. auto detection of handler functions is triggered by configuring webpack's "entry" to slsw.lib.entries ).

USE CASE

  1. You have a valid reason to split your serverless API projects up into many. Some example reasons for why one might want to split up there existing serverless API projects into separate serverless projects are as below: a.) Overcome CloudFormation template resource limits, but want to use the Shared API Gateway feature of the serverless framework. b.) A need to separate out end points into separate API gateways c.) Logic grouping of end points for better maintenance, CI or dev workflow scenarios
  2. You want to reference function handles from a shared code base in some parent directory that exists outside of the serverless project directory

PROPOSED IMPLEMENTATION In my view this feature could be easily implemented using by allowing the end user to add the "context" webpack config property to the webpack.config.js file, and then the serverless-webpack plugin uses that value as the working directory when searching for the function handler modules.

This would allow you to have multiple services with functions handlers that reference the same centralized code base which may exist outside of each serverless project directory.

Sample structure

-srcRoot

Similar or dependent issue(s): Couldn't find any matching exact same use case in this repo.

Additional Data

SebastianEdwards commented 6 years ago

Also, would find this really useful to avoid having to use relative paths everywhere.