![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
batch-import
Advanced tools
批量加载指定目录下node.js模块,并将模块导出结果保存到与模块路径结构一致的对象中
npm install batch-import --save
let batchImport = require('batch-import')
let modules = batchImport(options, container)
path
String - 指定模块加载目录
contain
Array - 仅加载指定模块,不能与exclude同时使用
exclude
Array - 排除指定模块,不能与contain同时使用
item
Function - 为每个匹配的单项添加自定义的数据过滤函数,实现类型检测、数据转换、预处理等操作
将模块导出结果添加到指定对象容器。
let batchImport = require('batch-import')
let modules = batchImport({
"middleware": {
"path": "middleware/",
"exclude": ["test.js"],
},
"models": {
"path": "models/",
item(data, completePath) {
if (typeof data === 'function') {
return data
} else {
throw `${completePath}模块输出数据类型错误,只接受函数类型`
}
}
},
"controllers": {
"path": "controllers/",
"contain": ["_route.js"],
},
})
配置项加载顺序与定义顺序一致,配置越靠前优先级越高
path路径以入口文件所在位置作为根路径
path路径中不应该出现./、../等相对路径表达式
FAQs
批量加载node.js模块、目录,并转换为对应的JS对象
The npm package batch-import receives a total of 2 weekly downloads. As such, batch-import popularity was classified as not popular.
We found that batch-import demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.