-
-
Notifications
You must be signed in to change notification settings - Fork 614
Description
- Rollup Plugin Name: node-resolve
- Rollup Plugin Version: 13.1.3
Feature Use Case
Currently, it appears that the resolveOnly property allows you to pass in an array of strings or regular expressions to validate if a plugin should be bundled in.
I had a use case where I wanted to bundle in everything except for certain dependencies. (node-rdkafka, sqlite3).
I would like to extend the resolveOnly property to allow developers more control.
This feature may already exist under another property, and if so, I apologize for the unnecessary recommendation.
Feature Proposal
While it is semi-possible to work around this by creating a complex regular expression to attempt to match everything except the given string, there are a few ways to introduce this.
Suggestion 1
I believe the best way to introduce this is to also allow resolveOnly to be a (plugin: string) => boolean function, thus allowing a developer to write something like:
function forbid (...plugins) {
const set = new Set(plugins)
return plugin => !set.has(plugins)
}
nodeResolve({
resolveOnly: forbid('sqlite3', 'node-rdkafka')
})By allowing the user to provide their own function, it gives them complete control to customize however they see fit.
Suggestion 2
While I believe suggestion 1 should be simple enough to implement, if you wanted to change just literally 1 type / 1 line of code, all you'd need to do is change out RegExp for { test: (plugin: string) => boolean }. I do not like this as much :)
function forbid (...plugins) {
const set = new Set(plugins)
return [{ test: plugin => !set.has(plugins) }]
}
nodeResolve({
resolveOnly: forbid('sqlite3', 'node-rdkafka')
})My current workaround
In order to work around this, I ended up doing the following:
function forbid (...plugins) {
const regex = new RegExp('');
const set = new Set(plugins)
regex.test = (pattern) => !set.has(pattern)
return [regex]
}While this works for now, I know it's a hack and could break at any minute :P
If someone likes the idea, I'm 100% willing to file the MR!