Giter Site home page Giter Site logo

serverless-build-plugin's Introduction

NOTICE: No longer maintained.


NPM ย  Build Status

Serverless Build Plugin

A Node.js focused build optimizer plugin for serverless.

Replaces packaging functionality for Node.JS functions.
Typically this will result in significant size reductions, especially with webpack

  • Bundling of functions in a Node.js friendly way
  • Arbitrary builds, with your own build file or a webpack config.

Docs:

serverless-build-plugin's People

Contributors

brendo avatar jtfell avatar nfour avatar ssansh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar

serverless-build-plugin's Issues

Optimization: Package function only once per build

In a scenario where we are packaging mutliple function zips pointing to the same handler, we can likely just cache that artifact in future to save on compute time, perhaps cloning it for each iteration in order for serverless to apply what it needs to apply.

Packager creates an broken ZIP archive

When using the build plugin, my Lambda deployments are broken as neither AWS nor my Mac can open the resulting zip files anymore. OSX throws an "Error 21 - is a directory."

I'm suspecting this is due to symbolic links or something in the node_modules, specifically in mysql redis, but I haven't had time to confirm this yet or to create a test project. Just wanted to let you know before I'm taking a closer look. It's noteworthy that the official packager of Serverless works without issues.

file build method requires .map files

The file build method currently requires .map files to be generated for each handler. I found that surprising, as I'm not used to including map files in production builds.

I got around this limitation by inserting the following into my webpack.config.js
devtool: 'source-map',

Support for custom transforms

The ability to have custom transformers, separate to the default Uglify and Babel.

  • Add transformers by a filename pointer (like handlers) in the config
  • Refactor transformer logic to resolve above
  • Let transformers determine file extension matching via static props
  • Force transforms to manipulate files, not in-memory blobs, for performance
  • Uglify should produce an inline source map like Babel

Excluding aws-sdk with webpack is not intuitive

I'm not sure this is a bug, but I found excluding the aws-sdk in a file build method using webpack unintuitive. Not only does it need to be excluded within the webpack.config.js using:
externals: ['aws-sdk']

But it also needs to excluded in the serverless.build.yml using

modules:
  exclude:
     - aws-sdk
  deepExclude: # Excluded from deep nested node_modules
    - aws-sdk

It seems odd to have to exclude it in both places.

TODO: refactor

  • Maintain full backward compat for serverless 1.0
  • Deprecate 0.5 support in @1.0 of this plugin, remove in @2.0
  • Rewrite in typescript
  • Add more tests
  • Add travis build system and publishing
  • Build typescript docs for the options objects via d.ts files

Warning in console output that no configuration was found

The build plugin works without configuration, assuming some default values.

This is usually undesirable I assume. Could the console output of the plugin be explicit about where it found configuration, or if it didn't find any?

How I can exclude some items, which I included?

Example:

# on serverless.build.yml
include:
  - application/api/**
  - core/**
  - services/**
  - configuration.js

exclude:
  - "**/__test__"
  - "**/.DS_Store"

I want to exclude those items from inside my include, one is a folder and another is a file.

include pattern not recoginized on Windows

Hi,

I am trying use include pattern as follows. It works fine when running serverless from Linux and Mac but not on Windows. serverless-build-plugin does not add [SOURCE] on Windows due to this.

functions:
  test:
    include:
      - dist/**

Thanks,
Abhishek

Unable to Deploy Single Function

there is a bug in the build plugin where you cannot deploy single functions... after building the plugin is expected by serverless to send artifect paths back to serverless for all functions... but only the path for the function being deployed is sent back... hence it crashes with error

Error --------------------------------------------------
 
     No artifact path is set for function: "another-function"

Use serverless' yaml parser

The serverless yaml parser is able to resolve file references

  • Create an init step to handle async actions like this
  • Duplicate functionality or rely on serverless' parser directly

Feature Request: Rename .jsx to .js when using babelify

For packaging I'm using babelify but not uglify as I prefer having separate files. It keeps the source more readable and shouldn't matter on the server too much anyway.

My project is based on React and uses .jsx as preferred file extension instead of .js. Dependent code such as myClass.jsx is still loaded via require('myClass') without the need to specify any extension. This works locally as this is handled transparently via Babel. However, after deploying to my backend, Babel isn't available anymore and thus require('myClass') will fail as the default Node environment wouldn't look for any .jsx files. A simple way to fix this would be to rename all .jsx to .js during packaging (if Babel if enabled).

For the time being I'm using this as a workaround:

require.extensions['.jsx'] = require.extensions['.js'];

require('myClass'); // now is able to load *.jsx, too

Would such a feature make sense for the build plugin in your opinion? How else would you approach this problem?

Issues with wrong functions deploying in 0.5

It appears there's a problem where the zip artifact file generated is being saved to the "this" variable. Given that serverless only instantiates the class once, and runs build() for every function, it can lead to a race condition where the variable is overwritten by other asynchronous running builds.

symlinks are not included in deployment package

I'm trying to bundle the npm package sharp which has symlinks. The package is added to my bundle however the symlinks are not included, causing my lambda to error out:

{
  "errorMessage": "libvips-cpp.so.42: cannot open shared object file: No such file or directory",
  "errorType": "Error",
  "stackTrace": [
    "Object.Module._extensions..node (module.js:597:18)",
    "Module.load (module.js:487:32)",
    "tryModuleLoad (module.js:446:12)",
    "Function.Module._load (module.js:438:3)",
    "Module.require (module.js:497:17)",
    "require (internal/module.js:20:19)",
    "Object.<anonymous> (/var/task/node_modules/sharp/lib/constructor.js:10:15)",
    "Module._compile (module.js:570:32)",
    "Object.Module._extensions..js (module.js:579:10)"
  ]
}

Invoke Local Broken

$ sls invoke local -l -f lunchBot

/Developer/Repositories/serverless-slack/lunchBot/handler.js:1
(function (exports, require, module, __filename, __dirname) { import request from 'request';
                                                              ^^^^^^
SyntaxError: Unexpected token import
...

serverless.yml

service: serverless-slack

provider:
  name: aws
  runtime: nodejs4.3

functions:
  lunchBot:
    handler: lunchBot/handler.default

plugins:
  - serverless-build-plugin

serverless.build.yml

method: bundle

sourceMaps: true
babel: true
uglify: false

modules:
  exclude:
    - aws-sdk

functions:
  lunchBot:
    include:
      - "lunchBot/**"

ModuleBundler is not adhearing to deepExcluded dependencies

There is an issue with the ModuleBundler.

It currently does check deepExclude but that won't matter when a module directly contains a node_modules folder - as that will be considered "part of" the module and thus included within it.

The solution will be to handle all node_modules directories. This may incur a slight rewrite.

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.