You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

serverless-webpack

Package Overview
Dependencies
Maintainers
0
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serverless-webpack

Serverless plugin to bundle your javascript with Webpack

5.15.1
latest
Source
npm
Version published
Weekly downloads
218K
4.81%
Maintainers
0
Weekly downloads
 
Created

What is serverless-webpack?

The serverless-webpack npm package is a Serverless Framework plugin that integrates Webpack to optimize and bundle your Serverless functions. It allows you to use Webpack's powerful features like tree shaking, code splitting, and module resolution to create optimized and efficient Serverless applications.

What are serverless-webpack's main functionalities?

Bundling

This feature allows you to bundle your Serverless functions using Webpack. The provided code sample demonstrates a basic Webpack configuration for bundling a handler.js file.

module.exports = {
  entry: './handler.js',
  target: 'node',
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: 'babel-loader'
      }
    ]
  },
  output: {
    libraryTarget: 'commonjs2',
    path: path.resolve(__dirname, '.webpack'),
    filename: 'handler.js'
  }
};

Tree Shaking

Tree shaking is a feature that eliminates dead code from your bundle. The code sample shows how to enable tree shaking by setting the mode to 'production' and using the 'usedExports' optimization option.

module.exports = {
  mode: 'production',
  entry: './handler.js',
  optimization: {
    usedExports: true
  },
  output: {
    libraryTarget: 'commonjs2',
    path: path.resolve(__dirname, '.webpack'),
    filename: 'handler.js'
  }
};

Code Splitting

Code splitting allows you to split your code into separate bundles, which can be loaded on demand. The code sample demonstrates how to configure Webpack to create separate bundles for 'handler.js' and 'anotherModule.js'.

module.exports = {
  entry: {
    handler: './handler.js',
    anotherModule: './anotherModule.js'
  },
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, '.webpack')
  }
};

Module Resolution

Module resolution allows you to create aliases for directories, making it easier to import modules. The code sample shows how to create an alias '@utils' for the 'src/utils/' directory.

module.exports = {
  resolve: {
    alias: {
      '@utils': path.resolve(__dirname, 'src/utils/')
    }
  },
  entry: './handler.js',
  output: {
    libraryTarget: 'commonjs2',
    path: path.resolve(__dirname, '.webpack'),
    filename: 'handler.js'
  }
};

Other packages similar to serverless-webpack

Keywords

serverless

FAQs

Package last updated on 12 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts