Hi All,
compilation warnings:
> Warning Cannot resolve 'TEST_ARRAY[argv.topic].backend'
/home/nilesh/component/index.js
Dynamic require may fail at run time, because the requested file
is unknown at compilation time and not included into executable.
Use a string literal as an argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option.
index.js:-
...
const {TEST_ARRAY} = require('./config/constants.file.js');
...
const
argv = require('./lib/sss.yargs.js').parseArgs(),
client = require(TEST_ARRAY[argv.topic].backend);
...
./config/constants.file.js:-
...
constants.TEST_ARRAY = {};
constants.TEST_ARRAY[constants.qqqqq] = {
description: ...,
backend: 'some value',
queue: ..,
logger: ...
}
...
./lib/sss.yargs.js:-
...
function parseArgs() {
const options = _buildOptions();
const descriptions = _buildDescriptions();
return require('yargs')
.usage('Usage: $0 -t <topic> -p <aaaaa> [-td <bbbbb>]')
.example(`$0 -t ${qqqqq} -p ${ccccc}`)
...
.help('h')
.alias('h', 'help')
.argv;
}
...
package.json
"bin":"index.js",
"pkg": {
"scripts": "./lib/**/*:./config/**/*",
"assets": "./lib/**/*:./config/**/*"
}
I'm using pkg with browserify for solving this kind of problems since browserify is smarter and have well-defined rules and plugins for require(), something like this:
browserify myappindex.js --no-bundle-external --no-builtins -o bundle.js
pkg -t node8-linux -c pkg.json -o execfile bundle.js
Thanks for the reply.
I will try using browserify.
Most helpful comment
I'm using pkg with browserify for solving this kind of problems since browserify is smarter and have well-defined rules and plugins for require(), something like this: