Socket
Socket
Sign inDemoInstall

serverless-webpack

Package Overview
Dependencies
Maintainers
1
Versions
66
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


Version published
Weekly downloads
203K
decreased by-8.41%
Maintainers
1
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

FAQs

Package last updated on 06 Sep 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc