npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

v-require-all

v1.0.5

Published

导入指定目录下的模块

Readme

v-require-all

用一个简单的方法来导入指定的文件(因NestJs导入模块而生).

在NestJs中使用

文件目录

├── assets
├── main.ts
├── modules
│   ├── app
│   │   ├── app.controller.ts
│   │   ├── app.module.ts
│   │   └── app.service.ts
│   ├── config
│   │   ├── config.controller.ts
│   │   ├── config.module.ts
│   │   └── config.service.ts
│   └── user
│       ├── user.controller.ts
│       ├── user.module.ts
│       └── user.service.ts
├── types
└── utils
    ├── requreAll.ts
    └── utils.ts

需求

将modules中所有xx.module.ts导入

实现

app.module.ts

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { requireAllInNest, Module } from "v-require-all";
import { join } from 'path';


@Module({
  imports: requireAllInNest({ dirname: join(__dirname, '..'), currentFile: __filename }, 'Module'),
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

config.module.ts

import { Module } from '@nestjs/common';
import { ConfigController } from './config.controller';
import { ConfigService } from './config.service';
import { defineDecorator } from "v-require-all";

@defineDecorator(['Module'])
@Module({
  imports: [],
  controllers: [ConfigController],
  providers: [ConfigService],
})
export class ConfigModule {}

user.config.ts

import { Module } from '@nestjs/common';
import { UserController } from './user.controller';
import { UserService } from './user.service';
import { defineDecorator } from "v-require-all";


@defineDecorator(['Module'])
@Module({
  imports: [],
  controllers: [UserController],
  providers: [UserService],
})
export class UserModule {}

说明

这个方法其实不只能导入指定目录的module, 也能导入controller或者service, 并且app.moudule中的@Module被重写后传入的参数也可以更灵活, 该方法也可不在NestJs中使用.

NestJs以外使用

import { requireAll } from 'v-require-all';

requireAll({ dirname: __dirname }).then(modules => {
  console.log(modules);
}).catch(error => {
  console.log(error);
});

执行结果

Map(3) {
  '/Users/zhangxuefei/Desktop/ra/package/a.ts' => { a: 'veloma', default: [Function: sum] },
  '/Users/zhangxuefei/Desktop/ra/package/b.ts' => { b: 'timer', default: [Function: sayHello] },
  '/Users/zhangxuefei/Desktop/ra/package/children/c.ts' => {
    name: '山竹',
    defineDecorator: [Function: defineDecorator],
    Person: [Function: Person],
    default: [Function: sayName]
  }
}

掘金文章(详细讲解)

https://juejin.cn/post/6976631747295313951/

联系方式

wx: __veloma__ emial: [email protected]