How do I build a single js file for AWS Lambda nodejs runtime

后端 未结 4 1515
不知归路
不知归路 2021-01-31 10:56

We are working on a project/framework that aids in deploying and maintaining code in AWS Lambda. I want to build/bundle all node.js code for a lambda function into one js file b

4条回答
  •  醉酒成梦
    2021-01-31 11:25

    aws-sdk-js now officially supports browserify. You can why this is a great thing on my blog.

    I have created a serverless plugin called serverless-plugin-browserify that will do all the heavy lifting with very minimal configuration.

    To answer the question specifically, I solved the problem with this browserify config:

    {
      disable: false, //Not an official option, used as internal option to skip browserify
      exclude: [],    //Not an option, but will use for setting browserify.exclude() if defined in yml
      ignore:  [],    //Not an option, but will use for setting browserify.ignore() if defined in yml
    
      basedir:          this.serverless.config.servicePath,
      entries:          [],
      standalone:       'lambda',
      browserField:     false,  // Setup for node app (copy logic of --node in bin/args.js)
      builtins:         false,
      commondir:        false,
      ignoreMissing:    true,  // Do not fail on missing optional dependencies
      detectGlobals:    true,  // We don't care if its slower, we want more mods to work
      insertGlobalVars: {      // Handle process https://github.com/substack/node-browserify/issues/1277
        //__filename: insertGlobals.lets.__filename,
        //__dirname: insertGlobals.lets.__dirname,
        process: function() {
        },
      },
      debug:            false,
    }
    

    You can see my full code here with a complete example here

提交回复
热议问题