serverless-webpack
Advanced tools
Comparing version
@@ -126,2 +126,7 @@ 'use strict'; | ||
.then(this.wpwatch), | ||
'before:offline:start:init': () => BbPromise.bind(this) | ||
.then(this.validate) | ||
.then(this.wpwatch), | ||
}; | ||
@@ -128,0 +133,0 @@ } |
@@ -17,3 +17,3 @@ 'use strict'; | ||
if (stats) { | ||
console.log("Webpack rebuilt"); | ||
console.log(stats.toString()); | ||
} | ||
@@ -20,0 +20,0 @@ }); |
{ | ||
"name": "serverless-webpack", | ||
"version": "1.0.0-rc.4", | ||
"version": "2.0.0", | ||
"description": "Serverless plugin to bundle your javascript with Webpack", | ||
@@ -27,3 +27,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "istanbul cover _mocha tests/all -- -R spec --recursive" | ||
"test": "istanbul cover ./node_modules/mocha/bin/_mocha tests/all -- -R spec --recursive" | ||
}, | ||
@@ -35,4 +35,3 @@ "dependencies": { | ||
"fs-extra": "^0.26.7", | ||
"npm-programmatic": "0.0.5", | ||
"webpack": "^1.13.1" | ||
"npm-programmatic": "0.0.5" | ||
}, | ||
@@ -47,3 +46,6 @@ "devDependencies": { | ||
"sinon-chai": "^2.8.0" | ||
}, | ||
"peerDependencies": { | ||
"webpack": "*" | ||
} | ||
} |
170
README.md
# Serverless Webpack | ||
[](http://www.serverless.com) | ||
[](https://circleci.com/gh/elastic-coders/serverless-webpack) | ||
[![Serverless][ico-serverless]][link-serverless] | ||
[![CircleCI][ico-circleci]][link-circleci] | ||
[![NPM][ico-npm]][link-npm] | ||
[![Contributors][ico-contributors]][link-contributors] | ||
A Serverless v1.0 plugin to build your lambda functions with [Webpack](https://webpack.github.io). | ||
A Serverless v1.x plugin to build your lambda functions with [Webpack][link-webpack]. | ||
This plugin is for you if you want to use the latest Javascript version with [Babel](https://babeljs.io/); | ||
use custom [resource loaders](https://webpack.github.io/docs/loaders.html); | ||
This plugin is for you if you want to use the latest Javascript version with [Babel][link-babel]; | ||
use custom [resource loaders][link-webpack-loaders]; | ||
try your lambda functions locally and much more! | ||
> **BREAKING CHANGE IN v2**: `webpack` must now be installed alongside `serverless-webpack` as a peer dependency. This allows more control over which version of Webpack to run. | ||
## Install | ||
```bash | ||
$ npm install serverless-webpack --save-dev | ||
``` | ||
npm install serverless-webpack | ||
``` | ||
@@ -28,3 +32,3 @@ Add the plugin to your `serverless.yml` file: | ||
By 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: | ||
Alternatively, you can specify a different file or configuration in `serverless.yml`: | ||
@@ -38,3 +42,3 @@ ```yaml | ||
```javascript | ||
```js | ||
// webpack.config.js | ||
@@ -53,6 +57,6 @@ | ||
generated to write bundles in the `.webpack` directory. If you set your own `output` | ||
configuration make sure to add a [`libraryTarget`](https://webpack.github.io/docs/configuration.html#output-librarytarget) | ||
configuration make sure to add a [`libraryTarget`][link-webpack-libtarget] | ||
for best compatibility with external dependencies: | ||
```javascript | ||
```js | ||
// webpack.config.js | ||
@@ -65,3 +69,3 @@ | ||
path: '.webpack', | ||
filename: 'handler.js', // this should match the first part of function handler in serverless.yml | ||
filename: 'handler.js', // this should match the first part of function handler in `serverless.yml` | ||
}, | ||
@@ -77,3 +81,3 @@ // ... | ||
In this case you might add external modules in | ||
[Webpack `externals` configuration](https://webpack.github.io/docs/configuration.html#externals). | ||
[Webpack's `externals` configuration][link-webpack-externals]. | ||
Those modules can be included in the Serverless bundle with the `webpackIncludeModules` | ||
@@ -104,3 +108,3 @@ option in `serverless.yml`: | ||
By default, the plugin will use the `package.json` file in working directory, If you want to | ||
use a different package conf, set `packagePath` to your custom package.json. eg: | ||
use a different package file, set `packagePath` to your custom `package.json`: | ||
@@ -115,3 +119,3 @@ ```yaml | ||
You can find an example setups in the [`examples`](./examples) folder. | ||
You can find an example setups in the [`examples`][link-examples] folder. | ||
@@ -124,33 +128,49 @@ ## Usage | ||
- Create the Serverless project with `serverless create -t aws-node` | ||
- Create the Serverless project with `serverless create -t aws-nodejs` | ||
- Install Serverless Webpack as above | ||
- Deploy with `serverless deploy` | ||
### Simulate API Gateway locally | ||
### Usage with serverless-offline | ||
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. | ||
The plugin integrates very well with [serverless-offline][link-serverless-offline] to | ||
simulate AWS Lambda and AWS API Gateway locally. | ||
Add the plugins to your `serverless.yml` file and make sure that `serverless-webpack` | ||
precedes `serverless-offline` as the order is important: | ||
```yaml | ||
plugins: | ||
... | ||
- serverless-webpack | ||
... | ||
- serverless-offline | ||
... | ||
``` | ||
serverless webpack serve | ||
``` | ||
Options are: | ||
Run `serverless offline` or `serverless offline start` to start the Lambda/API simulation. | ||
- `--port` or `-p` (optional) The local server port. Defaults to `8000` | ||
In comparison to `serverless offline`, the `start` command will fire an `init` and a `end` lifecycle hook which is needed for `serverless-offline` and e.g. `serverless-dynamodb-local` to switch off resources (see below). | ||
The `serve` command will automatically look for the local `serverless.yml` and serve | ||
all the `http` events. For example this configuration will generate a GET enpoint: | ||
#### Custom paths | ||
If you do not use the default path and override it in your Webpack configuration, | ||
you have use the `--location` option. | ||
#### serverless-dynamodb-local | ||
Configure your service the same as mentioned above, but additionally add the `serverless-dynamodb-local` | ||
plugin as follows: | ||
```yaml | ||
functions: | ||
hello: | ||
handler: handler.hello | ||
events: | ||
- http: | ||
method: get | ||
path: hello | ||
plugins: | ||
- serverless-webpack | ||
- serverless-dynamodb-local | ||
- serverless-offline | ||
``` | ||
Run `serverless offline start`. | ||
#### Other useful options | ||
You can reduce the clutter generated by `serverless-offline` with `--dontPrintOutput` and | ||
disable timeouts with `--noTimeout`. | ||
### Run a function locally | ||
@@ -160,5 +180,5 @@ | ||
```bash | ||
$ serverless webpack invoke --function <function-name> | ||
``` | ||
serverless webpack invoke --function <function-name> | ||
``` | ||
@@ -174,5 +194,5 @@ Options are: | ||
```bash | ||
$ serverless webpack watch --function <function-name> --path event.json | ||
``` | ||
serverless webpack watch --function <function-name> --path event.json | ||
``` | ||
@@ -188,5 +208,5 @@ Options are: | ||
```bash | ||
$ serverless webpack --out dist | ||
``` | ||
serverless webpack --out dist | ||
``` | ||
@@ -197,5 +217,37 @@ Options are: | ||
### Simulate API Gateway locally | ||
_There are plans to remove the integrated simulation functionality in favor of | ||
using serverless-offline (see [#135](https://github.com/elastic-coders/serverless-webpack/issues/135)) | ||
which already does the job perfectly and fully integrates with serverless-webpack. | ||
Please consider to switch to serverless-offline if you do not use it already._ | ||
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. | ||
```bash | ||
$ serverless webpack serve | ||
``` | ||
Options are: | ||
- `--port` or `-p` (optional) The local server port. Defaults to `8000` | ||
The `serve` command will automatically look for the local `serverless.yml` and serve | ||
all the `http` events. For example this configuration will generate a GET endpoint: | ||
```yaml | ||
functions: | ||
hello: | ||
handler: handler.hello | ||
events: | ||
- http: | ||
method: get | ||
path: hello | ||
``` | ||
## Example with Babel | ||
In the [`examples`](./examples) folder there is a Serverless project using this | ||
In the [`examples`][link-examples] folder there is a Serverless project using this | ||
plugin with Babel. To try it, from inside the example folder: | ||
@@ -205,1 +257,39 @@ | ||
- `serverless webpack run -f hello` to run the example function | ||
## Release Notes | ||
* 2.0.0 | ||
* Support arbitrary Webpack versions as peer dependency [#83][link-83] | ||
* Support `serverless offline start` invocation [#131][link-131] | ||
* Documentation updates [#88][link-88], [#132][link-132], [#140][link-140], [#141][link-141], [#144][link-144] | ||
* Print Webpack stats on recompile [#127][link-127] | ||
[ico-serverless]: http://public.serverless.com/badges/v3.svg | ||
[ico-circleci]: https://img.shields.io/circleci/project/github/elastic-coders/serverless-webpack.svg | ||
[ico-npm]: https://img.shields.io/npm/v/serverless-webpack.svg | ||
[ico-contributors]: https://img.shields.io/github/contributors/elastic-coders/serverless-webpack.svg | ||
[link-serverless]: http://www.serverless.com/ | ||
[link-circleci]: https://circleci.com/gh/elastic-coders/serverless-webpack/ | ||
[link-npm]: https://www.npmjs.com/package/serverless-webpack | ||
[link-contributors]: https://github.com/elastic-coders/serverless-webpack/graphs/contributors | ||
[link-webpack]: https://webpack.github.io/ | ||
[link-babel]: https://babeljs.io/ | ||
[link-webpack-loaders]: https://webpack.github.io/docs/loaders.html | ||
[link-webpack-libtarget]: https://webpack.github.io/docs/configuration.html#output-librarytarget | ||
[link-webpack-externals]: https://webpack.github.io/docs/configuration.html#externals | ||
[link-examples]: ./examples | ||
[link-serverless-offline]: https://www.npmjs.com/package/serverless-offline | ||
[link-serverless-dynamodb-local]: https://www.npmjs.com/package/serverless-dynamodb-local | ||
[comment]: # (Referenced issues) | ||
[link-83]: https://github.com/elastic-coders/serverless-webpack/pull/83 | ||
[link-88]: https://github.com/elastic-coders/serverless-webpack/pull/88 | ||
[link-127]: https://github.com/elastic-coders/serverless-webpack/pull/127 | ||
[link-131]: https://github.com/elastic-coders/serverless-webpack/pull/131 | ||
[link-132]: https://github.com/elastic-coders/serverless-webpack/pull/132 | ||
[link-140]: https://github.com/elastic-coders/serverless-webpack/pull/140 | ||
[link-141]: https://github.com/elastic-coders/serverless-webpack/issues/141 | ||
[link-144]: https://github.com/elastic-coders/serverless-webpack/issues/144 |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
-100%283
46.63%33011
-82.97%15
-57.14%592
-41.21%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed