Giter Site home page Giter Site logo

serverless-build-plugin's Introduction

SERVERLESS BUILD PLUGIN

*** WARNING *** This is a beta release under heavy development, use with caution.

This plugin is intended to add flexibility to the serverless build process for nodejs, under serverless 1.0 including an 0.5 compatibility layer thanks to zyrorl.

Currently in testing state. To try it:

npm i
cd test
npm i
export AWS_PROFILE=default
sls deploy
sls deploy function -f one
sls invoke -f one --log
sls deploy function -f one --method=file
sls invoke -f one --log

After running the above you should have built the same function in each of the two methods successfully.

Serverless 1.0.x-beta Installation

Run: npm i --save serverless-build-plugin

Add the plugin to serverless.yml under plugins

eg.

service: my-service

provider:
  name: aws
  runtime: nodejs4.3

plugins:
  - serverless-build-plugin

package:
    exclude:
        - node_modules

functions:
  one:
    handler: functions/one/handler.handler

Then create the serverless.build.yml as per Configuration.

Serverless 0.5.x Installation

Run: npm i --save serverless-build-plugin

Modify s-project.json to add serverless-build-plugin to the plugins array.

ie.

{
  "name": "example-serverless-project",
  "plugins": [
    "serverless-build-plugin"
  ],
  "description": "My Serverless Project",
  "version": "0.0.1",
  "profile": "serverless-v0.5.5"
}

Then create the serverless.build.yml as per Configuration.

METHODS

There are two ways to build:

  • Bundling
    • This will preserve the existing source filestructure and potentially any non-excluded files.
    • Optionally, each JS file in babel'ed and uglified individually
  • Build Files
    • With this method, specify a file (or let it default to a webpack.config.js)
    • The file can return a string, a stream or a webpack.config.js object
    • If the file exports a default function, its return value will instead be used, as above
    • Webpack configs will be executed, and their output injected into the zip, including externals modules
    • Strings & streams will be piped into a handler.js

CONFIGURATION

There are three ways to configure the plugin:

  • Create a serverless.build.yml inside the project directory
  • Populate custom.build in serverless.yml
  • The commandline
    • sls deploy function -f one --file=./buildFile.js
# ./serverless.build.yml

method: "bundle"

sourceMaps : true
babel      : true # Will use ./.babelrc
uglify     : true # Will use defaults

exclude:
  - "*" # Ignores the root directory

modules:
  exclude: # excluded from the root node_modules
    - aws-sdk

  deepExclude: # excluded from nested node_modules
    - aws-sdk

functions:
  one:
    include:
      - "functions/one/**"
      - "lib/one/**"

    exclude:
      - "**/*.json"

OPTIONS

  • babel
    • Can be true, will search for a .babelrc in the project directory
    • Can be a babelrc-like object
  • uglify
    • When true, will uglify source & modules
    • Can be an options object, passed to uglify
  • method
    • When bundle, will use bundling method
    • When file, will use a build file or webpack config
  • file
    • Path to a build file or webpack config

ROADBLOCKS

  • serverless 1.0 still doesn't support packaging single functions
  • sls deploy will currently take a while due to packaging everything for the first deployment.
    • This is a bug due to not being able to hook into it.

TODO

  • [email protected] support
  • sls deploy currently broken
    • Awaiting upstream bug fix
  • Make ServerlessBuildPlugin work on a per-function workflow
    • Awaiting upstream pull requests
  • Bundling based builds
    • Source code
      • Minified with uglifyjs, includes .map
      • Babelifie, includes .map
    • node_modules
      • Recursive resolution of non-dev dependencies
        • Also includes "meta" packages
      • Minified with uglifyjs
  • File based builds
    • Webpack
      • Partiy with severless-webpack-plugin
      • External node_modules are included
    • Build files
      • Can inherit a webpack config
      • Can pipe buffers and streams to a handler.js
  • Performs cleanup
  • Optimizations & refactors
    • Refactor out the plugin inheritence dependency
      • ModuleBundler
      • SourceBundler
      • FileBuild
      • Webpack
      • Babel
      • Uglify
    • Use serverless' built in yaml parser (which resolve recursively)
      • Requires an intialization step
    • Change transforms to write to file instead of memory
      • This could bloat memory quite a bit as it stands
    • Make webpack and babel-core peer dependencies
    • Inline source maps for uglifyjs

serverless-build-plugin's People

Contributors

nfour avatar

Watchers

 avatar  avatar

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.