Git Product home page Git Product logo

add-module-exports-webpack-plugin's Introduction

add-module-exports-webpack-plugin Build Status

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

License

MIT © Sindre Sorhus

add-module-exports-webpack-plugin's People

Contributors

samverschueren avatar sindresorhus avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.