Skip to content

Latest commit

 

History

History
163 lines (120 loc) · 5.68 KB

README.US.md

File metadata and controls

163 lines (120 loc) · 5.68 KB

@desco/env-require

NPM package that allows you to perform package imports available on the local machine instead of the one available in NPM.
Useful for the developer who is using his own package and wants to make changes without having to publish to test on the spot.

MIT License Version 3.0.1

🚀 Ready to use! 🚀

See other NPM projects here.

See other projects here.


📋 Table of Contents


⚙️ Installation

npm install --save @desco/env-require

Note that it will be necessary to have NPM installed for the command to work.


📦 Import

Node

const configEnvRequire = require("@desco/env-require")

Front

import configEnvRequire from "@desco/env-require"

📚 How to use

dynamicImports_dev.js

module.exports = {
  '@desco/atlas': () => require('../../atlas'),
}

dynamicImports.js

module.exports = {
  '@desco/atlas': () => require('@desco/atlas'),
  ...require('./dynamicImports_dev')
}

index.js

const envRequire = require('@desco/env-require')(packagesDynamicImports)

envRequire('@desco/atlas')

In dynamicImports_dev.js export an object containing in your keys the names of the packages and in their values ​​a function containing the loading of the local version of the package.

In dynamicImports.js export an object containing the names of the packages in its keys and in its values ​​a function containing the loading of the NPM version of the package.

At the end of the dynamicImports.js object, concatenate the importer values ​​of dynamicImports_dev.js, so the existing packages will overwrite the previous ones.

Import envRequire already running and passing the imported object from dynamicImports.js, that way it will already know which packages it will work with.

DynamicImports_dev.js should only be versioned with an empty object so that NPM packages are always used in production. After empty versioning, add dynamicImports_dev.js to .gitignore so that the changes for each programmer are not sent to production.

Make sure the local packages have the packages installed! (npm install)

Now just use envRequire instead of require / import!


🗂️ Scope

Eventually you may want to have two instances of envRequire, to do this just pass a second parameter with the name of the scope of each instance!

const envRequire = require('@desco/env-require')(packagesDynamicImports, 'main)
const envRequire = require('@desco/env-require')(packagesDynamicImports, 'second')

envRequire('@desco/atlas')
envRequire2('@desco/urano')

By default the scope name is default, so there is no need to pass a scope if you are using a single instance.


Author

Rafael A. R. Dias Email eu@diasrafael.com.br Linkedin @diasrafael Facebook @eudiasrafael GitHub Overview @descodifica GitHub NPM @desco-npm NPM @desco