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
- Host: GitHub
- URL: https://github.com/amarcruz/jscc-brunch
- Owner: aMarCruz
- License: mit
- Created: 2016-10-14T02:34:09.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-12-11T03:39:56.000Z (almost 7 years ago)
- Last Synced: 2025-02-17T11:42:56.610Z (8 months ago)
- Topics: brunch, brunch-plugin, comments, compilation, conditional, es6, javascript, preprocessor, sourcemap, typescript
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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');
//#endifmylib.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|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