简体   繁体   English

如何在 nodeJS CLI 应用程序中使用外部配置文件?

[英]How to use an external configuration file in an with nodeJS CLI Application?

I have a NodeJs CLI program.我有一个 NodeJs CLI 程序。 How to load an external configuration files in the program.如何在程序中加载外部配置文件。 Just like webpack-cli , it allows the users to customize the webpack.config.js file.就像webpack-cli一样,它允许用户自定义webpack.config.js文件。 How does it read the user's webpack.config.js file.它如何读取用户的webpack.config.js文件。

I tried the following, but it didn't work我尝试了以下方法,但没有奏效

require(path.resolve(process.cwd() ,  'some.config.js'));
// Cannot find module 'E:\code\some.config.js'

Checkout this package: https://www.npmjs.com/package/cli-config查看此 package: https://www.npmjs.com/package/cli-config

#!/usr/bin/env node
require('cli-config').run({dirname: __dirname, cmdTree: require(__dirname + '/lib'});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM