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 = ; moduleexports = // … output: filename: 'dist/index.js' libraryTarget: 'commonjs2' plugins: ;
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.
moduleexports arg1 + arg2;moduleexports arg1 - arg2;
This module re-exports them as follows.
module arg1 + arg2;moduleexports arg1 + arg2;moduleexports 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
- node-env-webpack-plugin - Simplified
NODE_ENV
handling - add-asset-webpack-plugin - Dynamically add an asset to the webpack graph