Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

add-module-exports-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

add-module-exports-webpack-plugin

Add `module.exports` for Babel and TypeScript compiled code

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-86.57%
Maintainers
1
Weekly downloads
 
Created
Source

[!WARNING] Deprecated. Prefer using JavaScript Modules instead of CommonJS.

add-module-exports-webpack-plugin

Add module.exports for Babel and TypeScript compiled code

When you use ES2015 modules with Babel or have a default export in TypeScript, they generate code which requires you to import it with require('x').default in CommonJS instead of require('x'). This plugin enables the latter.

Install

$ npm install add-module-exports-webpack-plugin

Usage

const AddModuleExportsPlugin = require('add-module-exports-webpack-plugin');

module.exports = {
	// …
	output: {
		filename: 'dist/index.js',
		libraryTarget: 'commonjs2'
	},
	plugins: [
		new AddModuleExportsPlugin()
	]
};

output.libraryTarget must be commonjs2

Primitive default exports

When exporting a primitive value as default export, other exported values will not be exported anymore. The reason is that this module redeclares the exports as follows.

module.exports.default = (arg1, arg2) => arg1 + arg2;
module.exports.subtract = (arg1, arg2) => arg1 - arg2;

This module re-exports them as follows.

module.exports = (arg1, arg2) => arg1 + arg2;
module.exports.default = (arg1, arg2) => arg1 + arg2;
module.exports.subtract = (arg1, arg2) => arg1 - arg2;

Because you can't attach properties to a primitive value, it's not possible to re-export the other properties and so you would end up with only a module.exports.

  • node-env-webpack-plugin - Simplified NODE_ENV handling
  • add-asset-webpack-plugin - Dynamically add an asset to the webpack graph

Keywords

FAQs

Package last updated on 30 Apr 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