Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/conartist6/babel-plugin-transform-package-self-reference
Transfroms package self-references by reading package.json
https://github.com/conartist6/babel-plugin-transform-package-self-reference
Last synced: 17 days ago
JSON representation
Transfroms package self-references by reading package.json
- Host: GitHub
- URL: https://github.com/conartist6/babel-plugin-transform-package-self-reference
- Owner: conartist6
- Created: 2020-12-08T15:54:03.000Z (about 4 years ago)
- Default Branch: trunk
- Last Pushed: 2020-12-13T01:41:09.000Z (about 4 years ago)
- Last Synced: 2024-10-29T11:46:11.456Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 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
```js
// package.json
{
name: 'my-package',
main: 'index.cjs',
exports: {
".": 'index.mjs'
},
}
``````js
// folder/file.js
import { foo } from "my-package";
const foo = require("my-package");// ↓ ↓ ↓
import { foo } from "../index.mjs";
const foo = require("../index.cjs");
```