# dynamic-import-js

> Generates an import file for all your JS and JSX files

Latest version **1.0.4** (published 2020-01-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install dynamic-import-js
pnpm add dynamic-import-js
yarn add dynamic-import-js
bun add dynamic-import-js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-01-28 |
| First published | 2020-01-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tomás de Lima |
| Maintainers | tomasdelima |
| Keywords | js, import, dynamic, require, automatic |

## Links

- npm: https://www.npmjs.com/package/dynamic-import-js
- Repository: https://github.com/tomasdelima/dynamic-import-js
- Homepage: https://github.com/tomasdelima/dynamic-import-js#readme
- Issues: https://github.com/tomasdelima/dynamic-import-js/issues
- npm.io page: https://npm.io/package/dynamic-import-js

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.4 (latest) — 2020-01-28
- 1.0.3 — 2020-01-16
- 1.0.2 — 2020-01-16
- 1.0.1 — 2020-01-16
- 1.0.0 — 2020-01-15

## README

A library to generate an importation file to require all local **JS** and **JSX** files.

# Installation

## Install the package

`npm install dynamic-import-js --save`

or

`yarn add dynamic-import-js --save`

## Configure the package

Add a file named `.dynamic-import-js.json` at the root folder with the following structure:

```
{
  "root": "./path/to/your/root/js/files",
  "exceptions": [
    "file-1.txt",
    "folder/file-2.js",
    ...
  ],
  "prefixlessFolders": [
    "folder-1",
    "folder-2/folder-3",
    ...
  ]
}
```

The key `root` is the path, relative to the project folder, where all `JS` and `JSX` files will be scanned.

The key `exceptions` is a list of files paths, relative to the `root` folder, that will not be included in the generated file.

The key `prefixlessFolders` is a list of folders that won't be used to form the assigned global resource. See **Naming Pattern**.

## Configure the `make-import` command

Merge the following with your `packaje.json` file:

```
{
  "scripts": {
    "make-import": "node ./node_modules/dynamic-import-js"
  }
}
```

# Usage

Run the following at the root folder:

`npm run make-import`

This will create a file named `local-modules.js` at the `root` path with all the `require` statements, globally assigned.

# Naming Pattern

Given a file, relative to `root`, named `Users/Form.js`, it's respective generated line will be `global.UsersForm = require('./Users/Form.js').default`.

Therefore, it is recommended to wisely name the folders, as they will be used to name the assigned global resources.

If, using the example above, the folder `Users` is included in the `prefixlessFolders`, the generated line would be `global.Form = require('./Users/Form.js').default`. This is particularly usefull for generic folders, such as `Components` or `Screens`.

---
_Source: https://npm.io/package/dynamic-import-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
