Serverless Plugin Parcel

homepage icon https://github.com/threadheap/serverless-plugin-parcel
Follow @threadheap

Tracked

NPM Downloads Last Month
36
Issues
1
Stars
4
Forks
0
Watchers
4
Watch Star Fork Issue Download License NPM Build Status Coverage Status Contributors

Repo README Contents:

serverless-plugin-parcel

serverless npm version

Serverless plugin for zero-config ES6/7 and Typescript support

This project is mostly a fork of serverless-plugin-typescript and was heavily inspired by that.

Features

Install

yarn add -D parcel-bundler serverless-plugin-parcel

or

npm install -D parcel-bundler serverless-plugin-parcel

Add the following plugin to your serverless.yml:

plugins:
    - serverless-plugin-parcel

Configure

By default, no configuration required, but you can change Parcel behavior by creating custom .babelrc file and in custom parcel section in serverless.yaml config:

custom:
    parcel:
        target: node
        cache: false

Check parceljs documentation for the full list of available options.

See example folder for a minimal example.

Automatic compilation

The normal Serverless deploy procedure will automatically compile with Parcel:

Usage with serverless-offline

The plugin integrates very well with serverless-offline to simulate AWS Lambda and AWS API Gateway locally.

Add the plugins to your serverless.yml file and make sure that serverless-plugin-parcel precedes serverless-offline as the order is important:

plugins: ...
    - serverless-plugin-parcel
    ...
    - serverless-offline
    ...

Run serverless offline or serverless offline start to start the Lambda/API simulation.

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)

serverless-dynamodb-local

Configure your service the same as mentioned above, but additionally add the serverless-dynamodb-local plugin as follows:

plugins:
    - serverless-plugin-parcel
    - serverless-dynamodb-local
    - serverless-offline

Run serverless offline start.

Run a function locally

To run your compiled functions locally you can:

$ serverless invoke local --function <function-name>

Options are:

Enabling source-maps

You can easily enable support for source-maps (making stacktraces easier to read) by installing and using the following plugin:

yarn add -D source-map-support
// inside of your function
import 'source-map-support/register';

or using babel plugin:

yarn add source-map-support
yarn add -D babel-plugin-source-map-support

in .babelrc:

{
    "plugins": [
        "source-map-support"
    ]
    ...
}

Alternatives

serverless-parcel