Skip to content
/ jscc Public

Tiny and powerful preprocessor for conditional comments and replacement of compile-time variables in text files

License

Notifications You must be signed in to change notification settings

aMarCruz/jscc

Repository files navigation

Build Status Issues Count Coverage npm License

jscc

Featuring some of the C preprocessor characteristics through special, configurable comments, jscc can be used in any type of files to build multiple versions of your software from the same code base.

With jscc, you have:

  • Conditional inclusion/exclusion of code, based on compile-time variables*
  • Compile-time variables with all the power of JavaScript expressions
  • Replacement of variables inside the source (by value at compile-time)
  • Source Map support

* This feature allows you the conditional declaration of ES6 imports (See the example).

jscc is not a minifier tool, it only does well that it does...

jscc is derived on jspreproc, the tiny source file preprocessor in JavaScript, enhanced with Source Map support but without the file importer (rollup and others does this better).

Install

npm i jscc -D

Usage

import jscc from 'jscc';
import { fs } from 'fs';

const source = fs.readFileSync('myfile.js', 'utf8')
const result = jscc(source)

Example

//#set _DEBUG 1

/*#if _DEBUG
import mylib from 'mylib-debug';
//#else */
import mylib from 'mylib';
//#endif
mylib.log('Starting v$_VERSION...');

output:

import mylib from 'mylib-debug';
mylib.log('Starting v1.0.0...');

That's it.

* jscc has the predefined _VERSION varname, in addition to _FILE.

Documentation

You can read in the Wiki about:

TODO

This is work in progress, so please update jscc constantly, I hope the first stable version does not take too long.

Expected:

  • Explanatory error messages, with location of the error
  • async mode
  • Better documentation*
  • Syntax hilighter for some editores
  • You tell me...

* For me, write in english is 10x harder than coding JS, so contributions are welcome...

Don't forget to give me your star!