New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-root-require

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-root-require

Transforms require module paths that have a prefix referring to the project root. Also works on `require.resolve`.

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

babel-plugin-root-require

Transforms require module paths that have a prefix referring to the project root. Also works on require.resolve.

install

npm install babel-plugin-root-require

example

file structure

  • src (project root)
    • foo
      • a.js
    • bar
      • b.js
      • baz
        • c.js
    • d.js

javascript

// these paths will work from any file in the project root (src)
require('~/foo/a')
require('~/bar/b')
require('~/bar/baz/c')
require('~/d')

// foo/a.js
require('~/d') // -> require('../d')

.babelrc

{
  "plugins": [
    ["root-require", {
      "projectRoot": "src"
    }]
  ]
}

terminal

babel src --out-dir build

options

prefix = '~'

Prefix that refers to the project root

projectRoot = process.cwd()

Absolute path of project root or relative path from process.cwd() to the project root which prefix refers to. Module paths will not be resolved correctly if this option is not correct. In the typical case that the source code is under the src directory, but babel is executed in the parent directory of src, set projectRoot: src.

long = false

By default, transformed module paths will be the most efficient path from the requiring file to the module. When long is true, the prefix will be transformed to the relative path up the tree to the project root and the rest of the path is untouched. In some cases, the module path will be longer this way, because the path goes up the tree to the project root and then back down the tree to the module.

Keywords

FAQs

Package last updated on 03 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc