As you are aware, this works if library found is iconv, but what if the fallback is on iconv-lite ?
'use strict';
var iconv_package;
var Iconv;
try {
// this is to fool browserify so it doesn't try (in vain) to install iconv.
iconv_package = 'iconv';
Iconv = require(iconv_package).Iconv;
} catch (E) {
// node-iconv not present
}
module.exports = Iconv;
webpack output
WARNING in ./~/encoding/lib/iconv-loader.js
9:12-34 Critical dependency: the request of a dependency is an expression`
I am using webpack more like a bundler to ship single-file functions at AWS lambda for execution(there is no npm available there) and to also bundle dependencies(binary files are bundled too, by a manual script I maintain)
This change removes any issues:
'use strict';
module.exports = require('iconv-lite').Iconv;
But it will probably blow-apart when the dep is iconv and not iconv-lite, I don't know how to solve this only for my project.
What if the wrapper is more like this ?
'use strict';
var Iconv = null;
// this is to fool browserify so it doesn't try (in vain) to install iconv.
try {
Iconv = require('iconv-lite').Iconv;
} catch (LE) {
try {
Iconv = require('iconv').Iconv;
} catch (E) {
// node-iconv not present
}
}
module.exports = Iconv;
As you are aware, this works if library found is
iconv, but what if the fallback is oniconv-lite?webpack output
I am using webpack more like a bundler to ship single-file functions at AWS lambda for execution(there is no npm available there) and to also bundle dependencies(binary files are bundled too, by a manual script I maintain)
This change removes any issues:
But it will probably blow-apart when the dep is
iconvand noticonv-lite, I don't know how to solve this only for my project.What if the wrapper is more like this ?