"rollup-plugin-ternary-replacement" is a plugin for popular web-applications builder called "rollup". This plugin can help developers to make their web-applications more compatible by replacing some of new ECMAScript features such as "??" operator by ternary operators. Replacing will be done automatically if plugin function call have been placed into rollup plugins configuration. Plugin convertion is performed without violating program logic and program flow disruptions. Different optional parameters allow to configurate plugin for developer's own needs. For example, developer can choose specific group of features that should be rapleced, or exclude certain files from conversion process. Plugin works correctly with both vanilla ECMAScript and framework syntax (also included jsx/tsx syntax).
npm install --save-dev rollup-plugin-ternary-replacement
yarn add --dev rollup-plugin-ternary-replacement
import replace from "rollup-plugin-ternary-replacement"
import rollupPluginTernaryReplacement from "rollup-plugin-ternary-replacement/types"
Replacing all admissible features with ternary operators.
import replace from "rollup-plugin-ternary-replacement";
export default [
input: "index.js",
output: [
{
file: "dist/index.js",
format: "es",
},
],
plugins: [replace()],
];
Replacing only logical assignments with ternary operators in particular files.
import replace from "rollup-plugin-ternary-replacement";
const config = {
exclude: ["excess-file.js"],
assignmentsOnly: true,
};
export default [
input: "index.js",
output: [
{
file: "dist/index.js",
format: "es",
},
],
plugins: [replace(config)],
];
Config name | Config type | Config appointment | Config values |
---|---|---|---|
exclude | Array | List of file/directory patterns that should be excluded from plugin launch | — |
excludeExtentions | Array | List of file extensions that should be excluded from plugin launch | — |
includeSourceMap | Boolean | enable source map flag | — |
nonNullMergesOnly | Boolean | transform assignments disable flag | — |
assignmentsOnly | Boolean | transform non-null merges disable flag | — |