Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/amarcruz/jscc

Tiny and powerful preprocessor for conditional comments and replacement of compile-time variables in text files
https://github.com/amarcruz/jscc

comments compilation conditional es6 html javascript jspreproc parser preprocessor replacement typescript

Last synced: 18 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# jscc

[![jscc on npm][npm-badge]][npm-url]
[![License MIT][license-badge]][license-url]
[![Linux Build][travis-badge]][travis-url]
[![Codacy][codacy-badge]][codacy-url]
[![Coverage][codecov-badge]][codecov-url]

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 blocks, based on compile-time variables*
- Compile-time variables with all the power of JavaScript expressions
- Replacement of variables in the sources, by its value at compile-time
- Sourcemap support, useful for JavaScript sources.
- TypeScript v3 definitions

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

jscc is derived on [jspreproc](http://amarcruz.github.io/jspreproc), the tiny source file preprocessor in JavaScript, enhanced with sourcemap support but without the file importer nor the removal of comments ([rollup](https://rollupjs.org/guide/en) with [rollup-plugin-cleanup](https://www.npmjs.com/package/rollup-plugin-cleanup) does it better).

jscc works in NodeJS 6 or later, with minimal dependencies and footprint. It was designed to operate on small to medium pieces of code (like most nowadays) and, since the whole process is done in memory, it is _really fast_.

jscc is **not** a minifier tool, but it does well what it does...

## Install

Use the instructions of the plugin for your toolchain:

- [Rollup](https://www.npmjs.com/package/rollup-plugin-jscc)
- [Brunch](https://www.npmjs.com/package/jscc-brunch)
- [Browserify](https://www.npmjs.com/package/jsccify)
- [Gulp](https://www.npmjs.com/package/gulp-jscc)
- [WebPack](https://github.com/OrangeLab/webpack-plugin-jscc) - Thanks to @duanlikang

or install the jscc package from npm if you need direct access to its API:

```sh
npm i jscc -D
```

### Direct Usage

```js
const jscc = require('jscc');

const result = jscc(sourceCode, options);

// or in async mode:
jscc(sourceCode, options, (err, result) => {
if (err) {
console.error(err);
} else {
console.log(result.code);
console.log(result.map);
}
})
```

The result is a plain JS object with a property `code`, a string with the processed source, and a property `map`, with a raw sourcemap object, if required by the `sourcemap` option (its default is `true`).

If a callback is provided, jscc will operate asynchronously and call the callback with an error object, if any, or `null` in the first parameter and the result in the second.

Please see the Wiki to know the supported [options](https://github.com/aMarCruz/jscc/wiki/Options).

## Directives

jscc works with _directives_ inserted in the text and prefixed with configurable character sequences, that defaults to `'/*'`, `'//'` and `'
[npm-badge]: https://img.shields.io/npm/v/jscc.svg
[npm-url]: https://www.npmjs.com/package/jscc
[license-badge]: https://img.shields.io/npm/l/jscc.svg?colorB=blue
[license-url]: https://github.com/aMarCruz/jscc/blob/master/LICENSE
[appveypr-badge]: https://ci.appveyor.com/api/projects/status/hdsef0p6q0oqr127?svg=true
[appveypr-url]: https://ci.appveyor.com/project/aMarCruz/jscc
[travis-badge]: https://img.shields.io/travis/aMarCruz/jscc.svg?label=travis
[travis-url]: https://travis-ci.org/aMarCruz/jscc
[snyk-badge]: https://snyk.io/test/github/aMarCruz/jscc/badge.svg?targetFile=package.json
[snyk-url]: https://snyk.io/test/github/aMarCruz/jscc?targetFile=package.json
[codacy-badge]: https://img.shields.io/codacy/grade/30e8679fcd614227837ad250dd6c4030.svg
[codacy-url]: https://www.codacy.com/app/aMarCruz/jscc?utm_source=github.com&utm_medium=referral&utm_content=aMarCruz/jscc&utm_campaign=Badge_Grade
[codecov-badge]: https://img.shields.io/codecov/c/github/aMarCruz/jscc.svg
[codecov-url]: https://codecov.io/gh/aMarCruz/jscc
[climate-badge]: https://codeclimate.com/github/aMarCruz/jscc/badges/gpa.svg
[climate-url]: https://codeclimate.com/github/aMarCruz/jscc
[commits-badge]: https://img.shields.io/github/last-commit/aMarCruz/jscc.svg
[commits-url]: https://github.com/aMarCruz/jscc/commits/master
[kofi-url]: https://ko-fi.com/C0C7LF7I