All Projects → aMarCruz → rollup-plugin-jscc

aMarCruz / rollup-plugin-jscc

Licence: MIT license
Conditional compilation and compile-time variable replacement for Rollup

Programming Languages

javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to rollup-plugin-jscc

rollup-plugin-sizes
Rollup plugin to display bundle contents & size information
Stars: ✭ 77 (+48.08%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-markdown
import JavaScript from Markdown code blocks
Stars: ✭ 16 (-69.23%)
Mutual labels:  rollup, rollup-plugin
postcss-font-grabber
A postcss plugin, it grabs remote font files and update your CSS, just like that.
Stars: ✭ 26 (-50%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-collect-sass
Collect Sass, then compile
Stars: ✭ 17 (-67.31%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-lit-css
Moved to https://github.com/bennypowers/lit-css
Stars: ✭ 35 (-32.69%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-purs
Bundles PureScript modules with Rollup
Stars: ✭ 71 (+36.54%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-userscript-metablock
Transform json file to userscript metablock and append on.
Stars: ✭ 26 (-50%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-closure-compiler-js
Rollup plugin for optimizing JavaScript with google-closure-compiler-js.
Stars: ✭ 31 (-40.38%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-html
Import HTML files as strings in rollup build
Stars: ✭ 36 (-30.77%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-generate-package-json
Generate package.json file with packages from your bundle using Rollup
Stars: ✭ 29 (-44.23%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-tagged-template
Use plain HTML files as tagged templates.
Stars: ✭ 24 (-53.85%)
Mutual labels:  rollup, rollup-plugin
web-config
A Rollup configuration to build modern web applications with sweet features as for example SCSS imports, Service Worker generation with Workbox, Karma testing, live reloading, coping resources, chunking, treeshaking, Typescript, license extraction, filesize visualizer, JSON import, budgets, build progress, minifying and compression with brotli a…
Stars: ✭ 17 (-67.31%)
Mutual labels:  rollup, rollup-plugin
svelte-typescript
Typescript monorepo for Svelte v3 (preprocess, template, types)
Stars: ✭ 214 (+311.54%)
Mutual labels:  preprocessor, rollup-plugin
rollup-plugin-generate-html-template
Rollup plugin for automatically injecting a script tag with the final bundle into an html file.
Stars: ✭ 58 (+11.54%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-inject-process-env
Inject environment variables in process.env with Rollup
Stars: ✭ 48 (-7.69%)
Mutual labels:  rollup, rollup-plugin
jscc
Tiny and powerful preprocessor for conditional comments and replacement of compile-time variables in text files
Stars: ✭ 44 (-15.38%)
Mutual labels:  preprocessor, jspreproc
rollup-plugin-external-globals
Transform external imports into global variables like output.globals.
Stars: ✭ 57 (+9.62%)
Mutual labels:  rollup, rollup-plugin
simple-cloud-music
简洁的的第三方网易云音乐播放器
Stars: ✭ 306 (+488.46%)
Mutual labels:  rollup
svelte-template-hot
Copy of official Svelte template with added HMR support
Stars: ✭ 61 (+17.31%)
Mutual labels:  rollup
sapper-typescript-esbuild-template
Sapper template with ESBuild and TypeScript
Stars: ✭ 18 (-65.38%)
Mutual labels:  rollup

rollup-plugin-jscc

npm Version Build Status AppVeyor Status Maintainability Test coverage License

Conditional compilation and compile-time variable replacement for Rollup.

rollup-plugin-jscc is not a transpiler, it is a wrapper of 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).

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, 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...

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

Thanks for your support!

Install

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

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:

/*#if _DEBUG
import mylib from 'mylib-debug';
//#else */
import mylib from 'mylib'
//#endif

mylib.log('Starting $_APPNAME v$_VERSION...')

output:

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 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 ['//', '/*', '<!--'] (with one optional space after them).
sourcemap boolean Must include a sourcemap?
Should be the same value as the property sourcemap of the Rollup output.
Default true
mapContent boolean Include the original source in the sourcemap, if sourceMap:true (the default).
Default true
values object Plain object defining the variables used by jscc during the preprocessing.
Default {}
extensions string | Array<string> Array of strings that specifies the file extensions to process.
Default ['js', 'jsx', 'ts', 'tsx', 'mjs', 'tag']
include string | Array<string> minimatch or array of minimatch patterns for paths that must be included in the processing.
exclude string | Array<string> minimatch or array of minimatch patterns for paths that should be ignored.

Directives

Please see the jscc wiki to know about directives used by jscc.

What's New

Please see the CHANGELOG.

License

The MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].