A Serverless v1.0 plugin to build your lambda functions with Webpack.
npm install serverless-webpack
Add the plugin to your serverless.yml file:
plugins:
- serverless-webpackBy default the plugin will look for a webpack.config.js in the service directory.
In alternative you can specify a different file or configuration in the serverless.yml with:
custom:
webpack: ./folder/my-webpack.config.jsNote that, if the output configuration is not set, it will automatically be
generated to write bundles in the .webpack directory.
The normal Serverless deploy procedure will automatically bundle with Webpack:
- Create the Serverless project with
serverless create -t aws-node - Install Serverless Webpack as above
- Deploy with
serverless deploy
To start a local server that will act like the API Gateway use the following command. Your code will be reloaded upon change so that every request to your local server will serve the latest code.
serverless webpack serve
Options are:
--portor-p(optional) The local server port. Defaults to8000
To run your bundled functions locally you can:
serverless webpack invoke --function <function-name>
Options are:
--functionor-f(required) is the name of the function to run--pathor-p(optional) is a JSON file path used as the function input event
Or to run a function every time the source files change use watch:
serverless webpack watch --function <function-name> --path event.json
Options are:
--functionor-f(required) is the name of the function to run--pathor-p(optional) is a JSON file path used as the function input event
To just bundle and see the output result use:
serverless webpack --out dist
Options are:
--outor-o(optional) The output directory. Defaults to.webpack.
In the example folder there is a Serverless project using this plugin with Babel.
To try it, from inside the example folder:
npm installto install dependenciesserverless webpack run -f helloto run the example function