babel-plugin-extension-resolver

1.0.12 • Public • Published

current version Build Status Coverage Status Mutation testing badge semantic-release Commitizen friendly

Resolve imports to more file extensions with a babel plugin

Example

With this file structure:

src/index.js
src/other.node.js
src/other.js
src/another.js

In:

// src/index.js
import other from './other';
import another from './another';
 
require('./other');
require('./another');

Out:

// lib/index.js
import other from './other.node.js';
import another from './another.js';
 
require('./other.node.js');
require('./another.js');

Install

npm install --save babel-plugin-extension-resolver

.babelrc

{
  "plugins": ["extension-resolver"]
}

With options:

{
  "plugins": [["extension-resolver", {
    "extensions": [".cool.js", ".js"]
  }]]
}

Options

extensions

Defaults: (similar to how create-react-app does it for web)

[
  '.node.mjs',
  '.mjs',
  '.node.js',
  '.js',
  '.node.ts',
  '.ts',
  '.node.tsx',
  '.tsx',
  '.json',
  '.node.jsx',
  '.jsx',
  '.node',
]

Warning: This overrides ALL extension resolution, notably .json and .node. Make sure to re-include all extensions that matter.

Readme

Keywords

Package Sidebar

Install

npm i babel-plugin-extension-resolver

Weekly Downloads

12

Version

1.0.12

License

MIT

Unpacked Size

11.2 kB

Total Files

5

Last publish

Collaborators

  • saiichihashimoto