Socket
Socket
Sign inDemoInstall

real-require

Package Overview
Dependencies
0
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    real-require

Keep require and import consistent after bundling or transpiling


Version published
Weekly downloads
4.6M
decreased by-0.29%
Maintainers
2
Install size
4.71 kB
Created
Weekly downloads
 

Readme

Source

real-require

Package Version Dependency Status Build

Keep require and import consistent after bundling or transpiling.

Installation

Just run:

npm install real-require

Usage

The package provides two drop-ins functions, realRequire and realImport, which can be used in scenarios where tools like transpilers or bundlers change the native require or await import calls.

The current realRequire functions only handles webpack at the moment, wrapping the __non_webpack__require__ implementation that webpack provides for the final bundle.

Example

// After bundling, real-require will be embedded in the bundle
const { realImport, realRequire } = require('real-require')

/*
  By using realRequire, at build time the module will not be embedded and at runtime it will try to load path from the local filesytem.
  This is useful in situations where the build tool does not support skipping modules to embed.
*/
const { join } = realRequire('path')

async function main() {
  // Similarly, this make sure the import call is not modified by the build tools
  const localFunction = await realImport('./source.js')

  localFunction()
}

main().catch(console.error)

Contributing

See CONTRIBUTING.md

License

Copyright Paolo Insogna and real-require contributors 2021. Licensed under the MIT License.

FAQs

Last updated on 25 Jul 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc