I'm trying to build a lib that works on both the browser & Node.js, with some slight differences. For instance, request should be done using the built-in browser's XMLHttpRequest
, & request-promise
on Node. Thus, I'd want rollup to completely ignore all import statements for request-promise
, because checks are done in my lib depending on the environment (browser or node) to switch from one behavior to another.
I've tried many ways:
module.exports = {
external: ['request-promise'],
}
// OR
const ignore = require( 'rollup-plugin-ignore' );
module.exports = {
plugins: [
ignore('request-promise'),
],
}
// OR
const hypothetical = require( 'rollup-plugin-hypothetical' );
module.exports = {
hypothetical({
files: {
'./node_modules/request-promise/lib/rp.js': `export default null;`
},
allowFallthrough: true,
}),
}
Nothing works... I always end up with a require statement, or a direct inclusion of the module in my output.
So, yeah, I'm struggling with it, and I'm praying for some help. I'm not really comfortable with module systems, or rollup itself, so do anybody knows how to just replace the request-promise
module with anything, even null
?
Cheers!