1.4.4 • Published 2 years ago

@prebuilder/rollup-plugin v1.4.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Prebuilder rollup plugin

C# like preprocessor directives for javascript

Install

npm i --save-dev @prebuilder/rollup-plugin

Usage

rollup.config.js :

import prebuilder from '@prebuilder/rollup-plugin';

let myDefines = [ 'MY_DIRECTIVE' ]

export default {
    input: "** your input **",
    output: {
        file: "** your output **",
    },
    plugins: [
        prebuilder({ defines: myDefines }),
    ],
}

source code :

class MyClass {

// if else directives:
#if MY_DIRECTIVE
    myFunction = (data) => {
        return data;
    }
#else
    myFunction = (differentData) => {
        return differentData;
    }
#endif

// commented mode & #if negative check:
//#if !MY_DIRECTIVE
    myVar = {
        number: 0
    };
//#else
    //#post-code myVar = {
    //#post-code     number: 5
    //#post-code };
//#endif

}

output code :

class MyClass {

    myFunction = (data) => {
        return data;
    }

    myVar = {
        number: 5
    };
}

Options

defines

Required. Type: Array<string>

List of defines based on which to validate #if statements.

include

Type: string || Array<string>

One or a list of script names to process, all other files will be ignored.

exclude

Type: string || Array<string>

One or a list of script names to ignore, ignores a file even if present in the include option.

log

Type: boolean

Wether to show this plugin's logs or not, like skipped files and number of #if groups found.

mode

Type: string

Values: "plain"|"commented"|"both"

Wether to preprocess directives written plainly #if or in a comment //#if. Default value is "both".

commented -> "//#if", "//#else", ... and "//#post-code let exampleVar = 5;"
plain     -> "#if", "#else", ... ("#post-code" not available)

Differences

The differences between this rollup plugin, and @prebuilder/rollup are: | | pb-rollup | rollup-plugin | | --- | :---: | :---: | | faster processing | ❌manages files +processes them | ✔ processes files | | Not affected by configurationedge cases | ✔ | ❌can become unusable for complex rollup configs, depending on what other plugin is used ¹ |

¹ ) If, for example, using the typsescript rollup plugin which seems to manage .ts files on non-transform hooks, @prebuilder/rollup is then more suitable.

v 1.1

  • added negative #if check (#if !value)

v 1.2

  • added include & exclude files option

v 1.3

  • added optional debug logging

v 1.3.1

  • improved log messages

v1.3.3

bugfixes:

  • incorrect code output when an if-else statement is unfulfilled

changes:

  • added debug log info on each processed "if group"
  • better debug log formatting

v1.3.4

  • Separated processing functions from plugin in a separate library. This allows for use with node & for other plugins.

v1.3.5

  • Update to rollup 3

v1.4.0

  • Added commented directives mode