Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aMarCruz/rollup-plugin-jscc
Conditional compilation and compile-time variable replacement for Rollup
https://github.com/aMarCruz/rollup-plugin-jscc
es6 javascript jscc jspreproc preprocessor rollup rollup-plugin typescript
Last synced: 25 days ago
JSON representation
Conditional compilation and compile-time variable replacement for Rollup
- Host: GitHub
- URL: https://github.com/aMarCruz/rollup-plugin-jscc
- Owner: aMarCruz
- License: mit
- Created: 2016-09-04T03:44:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-11-06T14:36:46.000Z (about 3 years ago)
- Last Synced: 2024-11-08T00:43:49.437Z (about 1 month ago)
- Topics: es6, javascript, jscc, jspreproc, preprocessor, rollup, rollup-plugin, typescript
- Language: JavaScript
- Homepage:
- Size: 148 KB
- Stars: 58
- Watchers: 3
- Forks: 9
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome - jscc
README
# rollup-plugin-jscc
[![npm Version][npm-badge]][npm-url]
[![Build Status][build-badge]][build-url]
[![AppVeyor Status][wbuild-badge]][wbuild-url]
[![Maintainability][climate-badge]][climate-url]
[![Test coverage][codecov-badge]][codecov-url]
[![License][license-badge]][license-url]Conditional compilation and compile-time variable replacement for [Rollup](http://rollupjs.org/).
rollup-plugin-jscc 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\* This feature allows you the conditional declaration of ES6 imports (See the [example](#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.
_**NOTE**_
The removal of non-jscc comments is not included, but you can use [rollup-plugin-cleanup](https://github.com/aMarCruz/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...
[][kofi-url]
Of course, feedback, PRs, and stars are also welcome 🙃
Thanks for your support!
## Install
```bash
npm i rollup-plugin-jscc -D
# or
yarn add rollup-plugin-jscc -D
```rollup-plugin-jscc requires rollup v2.0 and node.js v10.12 or later.
### Usage
rollup.config.js
```js
import { rollup } from 'rollup'
import jscc from 'rollup-plugin-jscc'export default {
input: 'src/main.js',
plugins: [
jscc({
values: { _APPNAME: 'My App', _DEBUG: 1 },
}),
],
//...other options
}
```in your source:
```js
/*#if _DEBUG
import mylib from 'mylib-debug';
//#else */
import mylib from 'mylib'
//#endifmylib.log('Starting $_APPNAME v$_VERSION...')
```output:
```js
import mylib from '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.
## Options
Plain JavaScript object, with all properties optional.
| Name | Type | Description |
| --- | --- | --- |
| asloader | boolean | If `false`, run the plugin as a `transformer`, otherwise run as `loader` (the default). |
| escapeQuotes | string | String with the type of quotes to escape in the output of strings: 'single', 'double' or 'both'.
**Default** nothing. |
| keepLines | boolean | Preserves the empty lines of directives and blocks that were removed.
Use this option with `sourceMap:false` if you are interested only in keeping the line numbering.
**Default** `false` |
| mapHires | boolean | Make a hi-res source-map, if `sourceMap:true` (the default).
**Default** `true` |
| prefixes | string | RegExp |
Array<string|RegExp> | The start of a directive. That is the characters before the '#', usually the start of comments.
**Default** `['//', '/*', '