Webpack Runtime for Serverless
A plugin to use Webpack to run and build your Serverless function.
🚀 For Serverless v1.0 check out the new implementation of this plugin called serverless-webpack.
This plugin is heavily inspired by serverless-runtime-babel and serverless-webpack-plugin.
- Runs locally and deploys functions bundled with Webpack
- Compile all your dependencies in a single JS file
- Use any loader you want, Babel with ES2015 and stage-0 presets is already bundled with this plugin
Note: Serverless v0.5.0 or higher is required.
- Install via npm in the root of your Serverless Project:
npm install serverless-runtime-webpack --save-dev
- In the
plugins
array in yours-project.json
add"serverless-runtime-webpack"
- Install the loaders you will use in your Webpack configuration
npm install babel-loader --save-dev
- All done!
All you need is to set runtime
property of s-function.json
to webpack
.
From scratch you can:
serverless project create
as usualserverless function create myfunc
and selectwebpack
when asked for a runtimeserverless function run myfun
done!
You can use serverless function create
as usual — it will prompt you for a runtime unless you add the -r webpack
flag.
GitHub stargazers example returns amount of starts for a GitHub repo.
Copy the stars
folder in a Serverless project configured with this plugin as described in the
Install section above; then run serverless function run stars
.
Configuration options can be used by setting the custom.runtime
of s-function.json
. The following options are available:
webpack
– The Webpack configuration also accepting an extra (optional) propertyconfigPath
with he path of the Webpack configuration file relative to the project
Example Webpack Runtime configuration with default values:
{
/*s-function.json*/
/*...*/
"runtime": "webpack",
"custom": {
"webpack": {
"configPath": "myfunc/webpack.config.js"
}
},
/*...*/
}