Socket
Socket
Sign inDemoInstall

rollup-plugin-commonjs

Package Overview
Dependencies
Maintainers
4
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-commonjs

Convert CommonJS modules to ES2015


Version published
Weekly downloads
334K
decreased by-7.99%
Maintainers
4
Weekly downloads
 
Created

What is rollup-plugin-commonjs?

The rollup-plugin-commonjs package is a Rollup plugin that allows you to convert CommonJS modules to ES6, so they can be included in a Rollup bundle. This is particularly useful for including npm packages that are only available in CommonJS format.

What are rollup-plugin-commonjs's main functionalities?

Convert CommonJS to ES6

This feature allows you to convert CommonJS modules to ES6 modules. The code sample demonstrates how to use the rollup-plugin-commonjs in a Rollup configuration file to convert CommonJS modules in the input file 'src/main.js' to ES6 modules in the output file 'bundle.js'.

const commonjs = require('@rollup/plugin-commonjs');

export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'cjs'
  },
  plugins: [commonjs()]
};

Named Exports

This feature allows you to specify named exports for CommonJS modules that do not have them. The code sample shows how to configure named exports for a module located at 'node_modules/my-library/index.js'.

const commonjs = require('@rollup/plugin-commonjs');

export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'cjs'
  },
  plugins: [
    commonjs({
      namedExports: {
        'node_modules/my-library/index.js': ['namedExport1', 'namedExport2']
      }
    })
  ]
};

Dynamic Requires

This feature allows you to handle dynamic requires in CommonJS modules. The code sample demonstrates how to configure the plugin to handle dynamic requires for all JavaScript files in the 'node_modules/my-library/' directory.

const commonjs = require('@rollup/plugin-commonjs');

export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'cjs'
  },
  plugins: [
    commonjs({
      dynamicRequireTargets: [
        'node_modules/my-library/**/*.js'
      ]
    })
  ]
};

Other packages similar to rollup-plugin-commonjs

FAQs

Package last updated on 05 Mar 2018

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