GithubHelp home page GithubHelp logo

jaydenseric / babel-plugin-transform-require-extensions Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 17 KB

A Babel plugin that transforms specified require path file extensions.

Home Page: https://npm.im/babel-plugin-transform-require-extensions

JavaScript 100.00%
babel esm npm

babel-plugin-transform-require-extensions's Introduction

babel-plugin-transform-require-extensions

npm version CI status

A Babel plugin that transforms specified require path file extensions.

This is useful for building dual ESM/CJS packages. File names with extensions are mandatory in ESM import specifiers in .mjs files. After transpiling this to CJS in .js files, the hardcoded .mjs extensions in the require paths must be transformed to .js. Alternatively, sometimes it’s safe to remove the extensions as Node.js in CJS mode can automatically resolve .js file extensions.

Setup

To install from npm run:

npm install babel-plugin-transform-require-extensions --save-dev

Configure Babel to use the plugin:

{ "plugins": ["transform-require-extensions"] }

This plugin must run after any ESM to CJS transpilation occurs.

By default .mjs extensions are transformed to .js. The extensions option can be used to specify extension replacements. For example, to remove .mjs extensions:

{
  "plugins": [
    [
      "transform-require-extensions",
      {
        "extensions": {
          ".mjs": ""
        }
      }
    ]
  ]
}

Support

  • Node.js v10+

babel-plugin-transform-require-extensions's People

Contributors

jaydenseric avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.