serverless-runtime-webpack
v0.3.0
Published
A Webpack runtime for the Serverless framework
Downloads
7
Maintainers
Readme
Webpack Runtime for Serverless
A plugin to use Webpack to run and build your Serverless function.
This plugin is heavily inspired by serverless-runtime-babel and serverless-webpack-plugin.
Features
- 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
Install
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!
Usage
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!
Scaffold
You can use serverless function create
as usual — it will prompt you for a runtime unless you add the -r webpack
flag.
Examples
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
.
Options
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
Example Webpack Runtime configuration with default values:
{
/*s-function.json*/
/*...*/
"runtime": "webpack",
"custom": {
"webpack": {
"configPath": "myfunc/webpack.config.js"
}
},
/*...*/
}