babel-plugin-transform-package-self-reference

0.1.4 • Public • Published

babel-plugin-transform-package-self-reference

Transforms package self-references in commonjs and es modules by changing the self-reference to a path relative to the importing file. Reads the closest package.json to get the package name and the path in the package to resolve the self reference to. If it is a transforming a require will resolve to the file specified in main. When transforming an import it will resolve to the file specified in exports['.'], or module if that is not found.

If you wish to short circuit the above logic and resolve to a custom path, specify a resolveTo path in the plugin's options object.

Examples

// package.json
{
  name: 'my-package',
  main: 'index.cjs',
  exports: {
    ".": 'index.mjs'
  },
}
// folder/file.js
import { foo } from "my-package";
const foo = require("my-package");

// ↓ ↓ ↓

import { foo } from "../index.mjs";
const foo = require("../index.cjs");

Package Sidebar

Install

npm i babel-plugin-transform-package-self-reference

Weekly Downloads

0

Version

0.1.4

License

MIT

Unpacked Size

4.07 kB

Total Files

6

Last publish

Collaborators

  • conartist6