babel-plugin-relativify-imports

0.1.1 • Public • Published

babel-plugin-relativify-imports

JavaScript Style Guide Build Status

Babel plugin to convert absolute import paths to relative paths.

Example, given this code in /src/folder/module.js:

import { OtherModule } from '/src/other-folder/other-module.js'
import '/src/folder/subfolder/submodule1.js'
 
async function getSubmodule2Lazily() {
  const { submodule2 } = await import('/src/folder/subfolder/submodule2.js')
  submodule2.method()
}
 
export * from '/src/folder/subfolder/submodule3.js'

Will become:

import { OtherModule } from '../other-folder/other-module.js'
import './subfolder/submodule1.js'
 
async function getSubmodule2Lazily() {
  const { submodule2 } = await import('./subfolder/submodule2.js')
  submodule2.method()
}
 
export * from './subfolder/submodule3.js'

Note: to convert bare module imports (import { Module } from '@organization/module'), please use cfware/babel-plugin-bare-import-rewrite before this plugin in your babel plugin chain.

Usage

Add to your project:

npm install babel-plugin-relativify-imports

Add relativify-imports to plugins in your babel settings:

{
  "plugins": ["relativify-imports"]
}

Contributing

Install

npm install

Test

npm test

Package Sidebar

Install

npm i babel-plugin-relativify-imports

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

9.9 kB

Total Files

8

Last publish

Collaborators

  • pdesjardins90