rollup-plugin-conditional
A proxy plugin for conditionally executing rollup plugins.
NOTE: This plugin has entered maintenance only mode, meaning that only bugs will be fixed. See But do I really need it
section to accomplish the same thing without a plugin.
Why
There are times when you only want to run a plugin if certain conditions are met. This plugin aims to simplify that setup.
But do I really need it?
Not really, in relatively newer versions on rollup you can accomplish the same thing using a simple spread mechanic:
... plugins: ...isProduction ? : ;
In the end, this syntax is better because:
- It reduces the cost of overhead and increases performance slightly
- It reduces your dependencies by one
Installation
npm install rollup-plugin-conditional --save-dev
Usage
;// import other plugins const isProduction = processenvbuildTarget === "PROD"; ... plugins: ... )
It's also possible to nest conditionals but the recommendation is to keep the plugins as flat as possible:
... plugins: ;
Special cases
Unfortunately some plugins, like rollup-plugin-serve, always assume that they will be executed so they perform some premature tasks before any of the life cycle hooks are called:
; ... plugins: ;
In order to work around this we need to defer the initialisation by simply providing a callback method that returns the plugins:
; ... plugins: ;
Backwards Compatibility Table
Rollup Version | Plugin Version |
---|---|
0.57+ | 3.x (Recommended) |
0.62 - 0.68.2 | 2.x |
< 62 | 1.x |
Versioning
This project uses semantic versioning