real-require
Keep require and import consistent after bundling or transpiling
Last updated 2 years ago by matteo.collina .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install real-require 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.2.0                                ...           latest (2 years ago)

2 Versions

  • 0.2.0                                ...           2 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (9)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |