Serverless Plugin Optimize

homepage icon https://github.com/FidelLimited/serverless-plugin-optimize

Tracked

NPM Downloads Last Month
3030
Issues
6
Stars
47
Forks
4
Watchers
47

Repo README Contents:

Serverless Optimize Plugin

serverless npm version npm downloads license

Bundle with Browserify, transpile with Babel and minify with Babili automatically to your NodeJS runtime compatible JavaScript.

This plugin is a child of the great serverless-optimizer-plugin. Kudos!

Requirements:

Setup

Install via npm in the root of your Serverless service:

npm install serverless-plugin-optimize --save-dev
plugins:
  - serverless-plugin-optimize
package:
  individually: true

Options

Configuration options can be set globally in custom property and inside each function in optimize property. Function options overwrite global options.

Global

custom:
  optimize:
    debug: true
    exclude: ['ajv']
    extensions: ['.extension']
    external: ['sharp']
    externalPath:
      sharp: 'external_modules/sharp'
    global: true
    ignore: ['ajv']
    includePaths: ['bin/some-binary-file']
    minify: false
    prefix: 'dist'
    plugins: ['transform-decorators-legacy']
    presets: ['es2017']

Function

functions:
  hello:
    optimize: false
functions:
  hello:
    optimize:
      exclude: ['ajv']
      extensions: ['.extension']
      external: ['sharp']
      externalPath:
        sharp: 'external_modules/sharp'
      global: false
      ignore: ['ajv']
      includePaths: ['bin/some-binary-file']
      minify: false
      plugins: ['transform-decorators-legacy']
      presets: ['es2017']

includePaths Files

There is a difference you must know between calling files locally and after optimization with includePaths.

When Optimize packages your functions, it bundles them inside /${prefix}/${functionName}/... and when your lambda function runs in AWS it will run from root /var/task/${prefix}/${functionName}/... and your CWD will be /var/task/.

Solution in #32 by @hlegendre. path.resolve(process.env.LAMBDA_TASK_ROOT, ${prefix}, process.env.AWS_LAMBDA_FUNCTION_NAME, ${includePathFile}).

Contribute

Help us making this plugin better and future proof.

License

This software is released under the MIT license. See the license file for more details.