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

https://github.com/amarcruz/jscc-brunch

Adds conditional compilation and compile-time variable replacement support to brunch
https://github.com/amarcruz/jscc-brunch

brunch brunch-plugin comments compilation conditional es6 javascript preprocessor sourcemap typescript

Last synced: 5 months ago
JSON representation

Adds conditional compilation and compile-time variable replacement support to brunch

Awesome Lists containing this project

README

          

# jscc-brunch

[![npm Version][npm-image]][npm-url]
[![License][license-image]][license-url]

Adds conditional compilation and compile-time variable replacement support to [brunch](http://brunch.io).

jscc-brunch is **not** a transpiler, it is a wrapper of [jscc](https://github.com/aMarCruz/jscc), a tiny and powerful, language agnostic file preprocessor that uses JavaScript to transform text based on expressions at compile time.

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

**IMPORTANT:**

From v2.8.3, the generation of source map is disabled by default to solve issues with many plugins that does not supports chained source maps. With sourceMaps disabled, jscc will only keep the correct line numbers.

Please read more about this in [Using Source Maps](#using-source-maps).

## Install

Install the plugin via npm with `npm i jscc-brunch -D`.

or, do manual install:

- Add `"jscc-brunch": "~x.y.z"` to `package.json` of your brunch app.
- If you want to use git version of plugin, use the GitHub URI `"jscc-brunch": "aMarCruz/jscc-brunch"`.

## Usage

In brunch **the order matters** and jscc is a preprocessor, so please put it before compilers in the devDependencies of your `package.json`.

Set the [options](#options) in your `brunch-config` file:

```js
...
plugins: {
jscc: {
values: {
_DEBUG: 1,
_MYAPP: 'My App' }
}
}
...
```

Use it:

```js
/*#if _DEBUG
const mylib = require('mylib-debug');
//#else */
const mylib = require('mylib');
//#endif

mylib.log('Starting $_MYAPP v$_VERSION...');
```

output:

```js
const mylib = require('mylib-debug');

mylib.log('Starting My App v1.0.0...');
```

That's it.

\* jscc has two predefined memvars: `_FILE` and `_VERSION`, in addition to giving access to the environment variables through the nodejs [`proccess.env`](https://nodejs.org/api/process.html#process_process_env) object.

See [Syntax](https://github.com/aMarCruz/jscc/wiki/Syntax) in the jscc wiki for information about templating.

## Options

Plain JavaScript object, with all properties optional.

Name | Type | Description
------------ | --------------- | -----------
escapeQuotes | string | String with the type of quotes to escape in the output of strings: 'single', 'double' or 'both'. This has no default.
prefixes | string | RegExp |
Array<string&vert;RegExp> | The start of a directive. That is the characters before the '#', usually the start of comments.
**Default** `'//'`, `'/*'`, `'
[][kofi-url]

Of course, feedback, PRs, and stars are also welcome 🙃

Thanks for your support!

## License

The [MIT License](LICENCE) (MIT)

Copyright (c) 2016-2018 Alberto Martínez

[npm-image]: https://img.shields.io/npm/v/jscc-brunch.svg
[npm-url]: https://www.npmjs.com/package/jscc-brunch
[license-image]: https://img.shields.io/npm/l/express.svg
[license-url]: https://github.com/aMarCruz/jscc-brunch/blob/master/LICENSE
[kofi-url]: https://ko-fi.com/C0C7LF7I
[1]: https://github.com/es128/anymatch