Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peternaydenov/dynamic-import
Function that allows you to dynamically import ES modules in your project. Works in Vite projects.
https://github.com/peternaydenov/dynamic-import
compatible dynamic es import modules vite
Last synced: 4 days ago
JSON representation
Function that allows you to dynamically import ES modules in your project. Works in Vite projects.
- Host: GitHub
- URL: https://github.com/peternaydenov/dynamic-import
- Owner: PeterNaydenov
- License: mit
- Created: 2023-10-02T09:01:34.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-09T07:48:40.000Z (7 days ago)
- Last Synced: 2024-11-09T08:29:42.334Z (7 days ago)
- Topics: compatible, dynamic, es, import, modules, vite
- Language: JavaScript
- Homepage:
- Size: 229 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# Dynamic Import (@peter.naydenov/dynamic-import)
![version](https://img.shields.io/github/package-json/v/peterNaydenov/dynamic-import)
![license](https://img.shields.io/github/license/peterNaydenov/dynamic-import)Function that allows you to dynamically import ES modules in your project. Works in **Vite** projects.
## Installation
```bash
npm i @peter.naydenov/dynamic-import
```## Usage
```js
// for es6 projects:
import dynamicImport from '@peter.naydenov/dynamic-import';// for commonjs projects:
const dynamicImport = require('@peter.naydenov/dynamic-import');// Provide first the import pattern function like this one:
const importPattern = (name) => import(`./modules/${name}.js`);
const importModules = dynamicImport ( importPattern );// Then use it to import modules:
importList = ['module1', 'module2', 'module3'];
importModules ( importList ) // Expect string[] and returns a promise
.then ( moduleList => {
// Do something with the moduleList
})
```## Credits
'@peter.naydenov/dynamic-import' was created and supported by Peter Naydenov.## License
'@peter.naydenov/dynamic-import' is released under the [MIT License](http://opensource.org/licenses/MIT).