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

babel-plugin-amd-default-export

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-amd-default-export

A Babel plugin to make the generated AMD modules export the default export directly and not wrapped in an object with a default property.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

babel-plugin-amd-default-export

Latest version Dependency status

A Babel plugin to make the AMD modules generated by @babel/plugin-transform-modules-amd export the default export directly and not wrapped in an object with a default property, which happen in Babel 6 and newer: { default: ... }. It will export just the exported value in module.exports, similarly to the return statement in an AMD module.

This plugin is supposed to be used especially with requirejs-babel7, which al,lows mixing AMD and ESM modules in one project and a consistent handling of default exports is necessary.

Table of Contents

Installation

This module can be installed in your project using NPM, PNPM or Yarn. Make sure, that you use Node.js version 6 or newer.

npm i -D babel-plugin-amd-default-export
pnpm i -D babel-plugin-amd-default-export
yarn add babel-plugin-amd-default-export

Babel Configuration Examples

Prevent the transpiler to wrap source files that are already wrapped by define or require as AMD modules:

{
  plugins: ['amd-default-export']
}

A typical configuration combined with @babel/plugin-transform-modules-amd:

{
  plugins: [
    'transform-modules-amd',
    'amd-default-export'
  ]
}

Another complete configuration example:

{
  plugins: [
    'amd-checker',
    'transform-modules-amd',
    [
      'module-resolver',
      {
        resolvePath: function (sourcePath, currentFile, opts) {
          // Avoid prefixing modules handled by other plugins.
          if (sourcePath.indexOf('!') < 0) {
            return 'es6!' + sourcePath;
          }
        }
      }
    ],
    [
      'amd-default-export',
      { addDefaultProperty: true }
    ]
  ]
}

The option addDefaultProperty enables setting the exported value to a default property in addition. It can improve the compatibility with consumers expecting the default export directly, or wrapped. It may interfere with some cases, where additional properties cannot be included in exported objects.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.

License

Copyright (c) 2022 Ferdinand Prantl

Licensed under the MIT license.

Keywords

FAQs

Package last updated on 06 Jan 2022

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