https://github.com/afeiship/next-try-require
Dynamic require with check if a dependency exists with webpack.
https://github.com/afeiship/next-try-require
dynamic next not-work require try
Last synced: about 1 year ago
JSON representation
Dynamic require with check if a dependency exists with webpack.
- Host: GitHub
- URL: https://github.com/afeiship/next-try-require
- Owner: afeiship
- License: mit
- Created: 2021-06-10T08:41:52.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-10T10:41:18.000Z (almost 5 years ago)
- Last Synced: 2025-03-09T03:35:12.918Z (about 1 year ago)
- Topics: dynamic, next, not-work, require, try
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# next-try-require
> Check if a dependency exists with webpack
[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]
## installation
```bash
npm install -S @jswork/next-try-require
```
## configuration
> project_root/config.js
```js
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
include: [
paths.appSrc,
path.join(__dirname, '../node_modules/@jswork/next-try-require/dist')
],
loader: require.resolve('babel-loader')
}
```
## usage
```conf
└── medias
├── animation.tsx
├── audio.tsx
├── document.tsx
├── image.tsx
├── unknown.tsx
└── video.tsx
```
```js
import '@jswork/next-try-require';
// .${context}${path}
// .${context}${defaults}
// @${context}${path}
// @${context}${defaults}
const MediaComponent = nx.tryRequire(
mediaType,
'unknown',
{ context: '/medias/'}
);
```
## license
Code released under [the MIT license](https://github.com/afeiship/next-try-require/blob/master/LICENSE.txt).
[version-image]: https://img.shields.io/npm/v/@jswork/next-try-require
[version-url]: https://npmjs.org/package/@jswork/next-try-require
[license-image]: https://img.shields.io/npm/l/@jswork/next-try-require
[license-url]: https://github.com/afeiship/next-try-require/blob/master/LICENSE.txt
[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/next-try-require
[size-url]: https://github.com/afeiship/next-try-require/blob/master/dist/next-try-require.min.js
[download-image]: https://img.shields.io/npm/dm/@jswork/next-try-require
[download-url]: https://www.npmjs.com/package/@jswork/next-try-require