native-require
v1.1.4
Published
To resolve external modules for bundlers
Downloads
6,502
Maintainers
Readme
native-require
Resolve requires in an easy way
Getting started
Install
$ npm install native-require --save
Require or Resolve from where you want
import _require from 'native-require'
// Seems normal but useful to resolve external modules when using bunlders
const axios = _require('axios')
// Require from specific directory
const model = _require.from('./src/model')
const User = model('./user')
// Alias
const User = model.require('./user')
Features
- Simple to use, no more you didn't need
- Relative requires from specific directory
- Resolve external warnings from bundlers (Webpack, Rollup, etc.)
- Higher performance (no
Module
will be created) - No dependencies
- Compatible in Node v4, v6 and v8
API
_require(request)
(default export)
Same as
require()
, but resolve external problems from bundlers
.require(request)
Alias of
_require()
.resolve(request)
Same as
require.resolve()
.from(basedir)
Create a new
native-require
instance but lookup modules frombasedir
One basedir
only create instance once, so never worry about used like
_require.from(modelDir).require('./user')
_require.from(modelDir).require('./post')
_require.from(modelDir).require('./comment')