Conditional compilation and compile-time variable replacement for Rollup.
With jscc, you have:
- Conditional inclusion/exclusion of blocks, based on compile-time variables*
- Replacement of variables in the sources, by its value at compile-time
- TypeScript v3 definitions
* This feature allows you the conditional declaration of ES6 imports (See the example).
Since jscc is a preprocessor, rollup-plugin-jscc is implemented as a file loader, so it runs before any transpiler and is invisible to them. This behavior allows you to use it in a wide range of file types but, if necessary, it can be used as a Rollup transformer instead of a loader.
The removal of non-jscc comments is not included, but you can use rollup-plugin-cleanup, which brings compaction and normalization of lines in addition to the conditional removal of JS comments.
Support my Work
I'm a full-stack developer with more than 20 year of experience and I try to share most of my work for free and help others, but this takes a significant amount of time, effort and coffee so, if you like my work, please consider...
Of course, feedback, PRs, and stars are also welcome 🙃
Thanks for your support!
npm i rollup-plugin-jscc -D# oryarn add rollup-plugin-jscc -D
rollup-plugin-jscc requires rollup v2.0 and node.js v10.12 or later.
input: 'src/main.js'plugins://...other options
in your source:
/*#if _DEBUGimport mylib from 'mylib-debug';//#else *///#endifmylib
* jscc has two predefined memvars:
_VERSION, in addition to giving access to the environment variables through the nodejs
|escapeQuotes||string||String with the type of quotes to escape in the output of strings: 'single', 'double' or 'both'.
|keepLines||boolean||Preserves the empty lines of directives and blocks that were removed.
Use this option with
|mapHires||boolean||Make a hi-res source-map, if
|prefixes||string | RegExp |
|The start of a directive. That is the characters before the '#', usually the start of comments.
|sourcemap||boolean||Must include a sourcemap?
Should be the same value as the property
|mapContent||boolean||Include the original source in the sourcemap, if
|values||object||Plain object defining the variables used by jscc during the preprocessing.
|extensions||string | Array<string>||Array of strings that specifies the file extensions to process.
|include||string | Array<string>||minimatch or array of minimatch patterns for paths that must be included in the processing.|
|exclude||string | Array<string>||minimatch or array of minimatch patterns for paths that should be ignored.|
Please see the jscc wiki to know about directives used by jscc.
Please see the CHANGELOG.
The MIT License