You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 9, 2023. It is now read-only.
Rollup support multiple outputs with the same input. But sometime we want to apply different plugins for these outputs.
The most common scenario is apply the terser plugin for a minify bundle.
Before we can write a config array, but there are a lot of duplicate code and operations.
This plugin (maybe not a plugin) gives you a slightly elegant and efficient solution for this scene.
{// ...plugins: plugins(pluginA,[filter,pluginB],// same as whenpluginsC, ...,[anotherFilter,pluginD,pluginE]// same as whenAll and flat)}
The filter is a predicate function, the parameter is an output config object. If the filter return a truthy value, the rest plugins will be apply for the output.
when and whenAll is convenient for few filters and plugins is convenient for multiple filters.
Filter helpers
There are three simple but useful filter helpers: prop, format, file.
With them you can write like:
// output [{name: pkg.name,file: pkg.browser,format: 'umd'}]when(format('umd'),pluginA)// same aswhen(format(/^umd$/),pluginA)// same aswhen(format(f=>f==='umd'),pluginA)when(file(pkg.browser),pluginA)format=filter=>prop('format',filter)file=filter=>prop('file',filter)