Giter VIP home page Giter VIP logo

serverless-plugin-parcel's Introduction

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

  • Zero-config: Works out of the box without the need to install any other compiler or plugins
  • Supports sls package, sls deploy and sls deploy function
  • Supports sls invoke local
  • Integrates nicely with serverless-offline

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:

  • Create the Serverless project with serverless create -t aws-nodejs
  • Install Serverless Parcel Plugin as above
  • Deploy with serverless deploy

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:

  • --function or -f (required) is the name of the function to run
  • --path or -p (optional) path to JSON or YAML file holding input data
  • --data or -d (optional) input data

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

Author

Pavel Vlasov

serverless-plugin-parcel's People

Contributors

dependabot[bot] avatar pavelvlasov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

serverless-plugin-parcel's Issues

package individually not working

Hey,
I have 2 functions that I'm trying to package separately.
The sls package process generates 2 zips in /.serverless, and they both contain 2 js files, 1 for each function.
Is there a way to do a separate build so every zip will contain only one function?

is there a possibility to include node_modules as part of the packaged zip

We have issues with dynamic imports with lazy loading on one of our dependencies, parcel doesn't handle that package well. is it possible to include that as an external module in the zip?

In fact, I would prefer keeping all the node_modules as external, while there is an option to not build node_modules, I didn't find any way to add the non-dev node_modules in the generated zip file.

Is there a way to achieve this?

Custom buildFolder/outDir

I'm trying to keep my local directory structure clean, and I'd like this plugin to use my custom.parcel.outDir setting, rather than the hardcoded buildFolder. It doesn't seem like a particularly big change, and I'd be happy to submit a PR if you're ok with it. Thanks!

Bundle using Parcel2

Hi,
I have some problems when trying to bundle code that uses @sentry/serverless due to dependency perf_hooks
Parcel errors out: Cannot resolve dependency 'perf_hooks'.

It seems that this issue is solved in parcel2.

Is it possible to use this plugin with this new version?

Crash when multiple functions are defined in serverless.yaml

Hi ๐Ÿ‘‹

Thanks for the plugin, but I'm having an issue when multiple functions are defined into serverless.yaml for instance:

functions:
  foo:
    handler: src/index.foo
    events:
      - http: POST foo
  bar:
    handler: src/index.bar
    events:
      - http: POST bar

๐Ÿšจ Cannot add a worker call if workerfarm is ending.

Do you have any workaround? Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.