All Projects → sindresorhus → add-module-exports-webpack-plugin

sindresorhus / add-module-exports-webpack-plugin

Licence: MIT License
Add `module.exports` for Babel and TypeScript compiled code

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to add-module-exports-webpack-plugin

Handlebars Webpack Plugin
Renders your html-template at build time
Stars: ✭ 135 (+275%)
Mutual labels:  webpack-plugin, npm-package
Add Asset Webpack Plugin
Dynamically add an asset to the Webpack graph
Stars: ✭ 84 (+133.33%)
Mutual labels:  webpack-plugin, npm-package
Node Env Webpack Plugin
Simplified `NODE_ENV` handling with webpack
Stars: ✭ 51 (+41.67%)
Mutual labels:  webpack-plugin, npm-package
2018-package-three-webpack-plugin
[ARCHIVED] Webpack plugin to use Three.js "examples" classes
Stars: ✭ 45 (+25%)
Mutual labels:  webpack-plugin, npm-package
react-native-value-picker
Cross-Platform iOS(ish) style picker for react native.
Stars: ✭ 18 (-50%)
Mutual labels:  npm-package
is-safe-integer
ES2015 Number.isSafeInteger() ponyfill
Stars: ✭ 16 (-55.56%)
Mutual labels:  npm-package
next-gen-ui
www.npmjs.com/package/next-gen-ui
Stars: ✭ 24 (-33.33%)
Mutual labels:  npm-package
asset-graph-webpack-plugin
Webpack plugin to easily get assets dependency graph based on entry point
Stars: ✭ 13 (-63.89%)
Mutual labels:  webpack-plugin
braille
A Node module for converting text to Braille alphabet.
Stars: ✭ 18 (-50%)
Mutual labels:  npm-package
fritz-box
📦 Promise-based JavaScript FRITZ!Box API.
Stars: ✭ 14 (-61.11%)
Mutual labels:  npm-package
github-profile-card
Simple and easy to use widget with your GitHub profile — No dependencies
Stars: ✭ 98 (+172.22%)
Mutual labels:  npm-package
tinyimg-webpack-plugin
A webpack plugin for compressing image
Stars: ✭ 61 (+69.44%)
Mutual labels:  webpack-plugin
bundle-inspector-webpack-plugin
Bundle Inspector | Analysis Tool for Webpack
Stars: ✭ 19 (-47.22%)
Mutual labels:  webpack-plugin
couchbase-index-manager
Command-line interface to manage Couchbase indexes, synchronizing them to index definitions.
Stars: ✭ 14 (-61.11%)
Mutual labels:  npm-package
react-innertext
Returns the innerText of a React JSX object.
Stars: ✭ 37 (+2.78%)
Mutual labels:  npm-package
Nodorithm
NPM package for algorithms.
Stars: ✭ 22 (-38.89%)
Mutual labels:  npm-package
kladi
Easy to use state management library for React
Stars: ✭ 24 (-33.33%)
Mutual labels:  npm-package
skygear-SDK-JS
Skygear SDK for JavaScript
Stars: ✭ 25 (-30.56%)
Mutual labels:  npm-package
prettier-webpack-plugin
Process your Webpack dependencies with Prettier
Stars: ✭ 47 (+30.56%)
Mutual labels:  webpack-plugin
conditional-expression
JavaScript functional conditional expression
Stars: ✭ 63 (+75%)
Mutual labels:  npm-package

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.

Related

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].