Serverless Cljs Plugin

Enables Clojurescript as an implementation language for Lambda handlers

serverless-cljs-plugin

npm version

A Serverless plugin which uses lein/cljs-lambda (or, optionally Lumo) to package services written in Clojurescript.

Leiningen Template

$ lein new serverless-cljs example
example$ lein deps

Will generate an example directory containing a minimal serverless.yml and project.clj demonstrating this plugin's functionality.

Guide to using the plugin via Lein/JVM compilation.

Usage

functions:
  echo:
    cljs: example.core/echo

plugins:
 - serverless-cljs-plugin

With the above serverless.yml, serverless deploy will create a zip file containing your functions. Doing this is similar to setting the Serverless packaging.artifact option - cljs-lambda is responsible for the zip contents, and Serverless includes/excludes will be skipped (cljs-lambda offers equivalent functionality).

In the example above, there needn't be a corresponding entry for echo in project.clj.

Lumo

Alternatively you can use the Lumo compiler.

In order to enable it, pass the --lumo switch to either deploy or package:

$ serverless deploy --lumo

Or add the following to your serverless.yml:

custom:
  cljsCompiler: lumo
  • Compiler options

    The source paths and compiler options will be read from the optional file serverless-lumo.edn. Below are the defaults:

    {:source-paths ["src"]
     :compiler     {:output-to     "out/lambda.js"
                    :output-dir    "out"
                    :source-map    false ;; because of a bug in lumo <= 1.8.0
                    :target        :nodejs
                    :optimizations :none}}
  • Lumo Configuration

    As an alternative to cljsCompiler: lumo, cljsCompiler.lumo may be specified as a map of options. These options are passed directly to the lumo process. Currently supported:

    custom:
      cljsCompiler:
        lumo:
          dependencies:
            - andare:0.7.0
          classpath:
            - /tmp/
          localRepo: /xyz
          cache: /cache | none
          index: true | false
          exitOnWarning: true | false

    Note: caching is always on unless you specify "none" in the config.

  • The index.js file

    The index option will materialize a custom index.js in :output-dir's parent folder. This file should be thought as managed by serverless-cljs-plugin and it is necessary for some plugin (e.g.: serverless-offline) to work properly.

    Note: with the default compiler options, index.js will be saved in the project root, overwriting without warning.

  • Exit on compilation warnings

    Lumo generates warnings such as WARNING: Use of undeclared Var to signal failures. You can tune the ones you want to see by using the :warnings compiler option in serverless-lumo.edn, but by default the lumo process emits the warnings, does not throw and returns 0. This means that serverless will keep going in presence of warnings.

License

serverless-cljs-plugin is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying LICENSE file.

view on Github

Latest commit b2f54ec on Sep 24, 2017

New to serverless?

To get started, pop open your terminal & run:

npm install serverless -g