@teages/nitro-glob-import
v0.0.2
Published
A module to provide glob import for Nitro Server.
Downloads
1
Readme
@teages/nitro-glob-import
A module to provide glob import for Nitro Server.
Usage
Install package:
Make sure you have nitro installed.
# npm
npm install @teages/nitro-glob-import
# yarn
yarn add @teages/nitro-glob-import
# pnpm
pnpm install @teages/nitro-glob-import
# bun
bun install @teages/nitro-glob-import
How to use:
- In your
nitro.config.ts
file, import the package and add it to themodules
array.
import nitroGlobImport from '@teages/nitro-glob-import'
export default defineNitroConfig({
modules: [
nitroGlobImport([{
path: '#glob-test',
globInput: ['./func/*.ts'],
}]),
],
})
- Then you can import the module in your code.
import loaders from '#glob-test'
const { yourFunc } = await loaders['./func/a.ts']()
What is the package for?
Some time you need to import a lot of file from some folder, such as graphql api:
src
├── graphql
│ ├── mutation
│ │ ├── a.ts
│ │ ├── b.ts
│ ├── query
│ │ ├── c.ts
In this case, you need to add a lot of import codes.
With this package, you just need to:
import nitroGlobImport from '@teages/nitro-glob-import'
export default defineNitroConfig({
modules: [
nitroGlobImport([{
path: '#gql-schema',
globInput: ['./schema/*.ts'],
}]),
],
})
Then you can get all in one variable, and no longer need to maintain import code.
Development
- Clone this repository
- Install latest LTS version of Node.js
- Enable Corepack using
corepack enable
- Install dependencies using
pnpm install
and thenpnpm dev:prepare
- Run interactive tests using
pnpm dev
License
Published under MIT License.