rollup-plugin-conditional-compilation 0.0.3 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,9 +3,15 @@
3
3
  [![npm version](https://img.shields.io/npm/v/rollup-plugin-conditional-compilation.svg)](https://www.npmjs.com/package/rollup-plugin-conditional-compilation) [![npm downloads](http://img.shields.io/npm/dm/rollup-plugin-conditional-compilation.svg)](https://npmcharts.com/compare/rollup-plugin-conditional-compilation,token-types?start=1200&interval=30)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/59dd6795e61949fb97066ca52e6097ef)](https://www.codacy.com/app/Borewit/rollup-plugin-conditional-compilation?utm_source=github.com&utm_medium=referral&utm_content=Borewit/rollup-plugin-conditional-compilation&utm_campaign=Badge_Grade)
5
5
 
6
- A simple plugin that allows you to include or exclude code blocks based on compile-time conditions. Works like `#if`, `#endif` in C/C++.
6
+ A simple plugin that allows you to include or exclude code blocks based on compile-time conditions. Same as `#if`, `#else`, `#elif` , `#endif` in C/C++, it looks like this:
7
7
 
8
- > **Note**: This plugin is a simplified version that only supports `#if` and `#endif` for now. Supports for `#else`, `#elif` will be added in future releases.
8
+ ```typescript
9
+ // #if DEBUG
10
+ console.log('user', userData); // when DEBUG is false, this line will be removed
11
+ // #endif
12
+ ```
13
+
14
+ > **Note**: You should modify the plugin options to ensure **NOT to strip comments so quickly**, since we work with them. For example, with `@rollup/plugin-typescript`, set `removeComments: false`.
9
15
 
10
16
  **More Rollup plugins** you might be interested in:
11
17
 
@@ -25,31 +31,42 @@ pnpm add -D rollup-plugin-conditional-compilation
25
31
 
26
32
  ```js
27
33
  import conditional from 'rollup-plugin-conditional-compilation';
28
-
29
34
  export default {
30
- input: 'src/index.js',
31
- output: { file: 'dist/bundle.js', format: 'esm' },
32
35
  ...other configs,
33
- plugins: [conditional({ variables: { DEBUG: false, FEATURE_X: true } })],
36
+ plugins: [
37
+ typescript({
38
+ ...,
39
+ removeComments: false, // !!IMPORTANT!! Don't strip comments so quickly!
40
+ }),
41
+ conditional({ variables: { DEBUG: false, FEATURE_X: true } })
42
+ ],
34
43
  };
35
44
  ```
36
45
 
37
46
  ### Syntax
38
47
 
39
- - Single-line directives only: `// #if <expression>` and `// #endif`.
48
+ - Single-line directives only: `// #if <expression>`, `// #else`, `// #elif <expression>` and `// #endif`.
40
49
  - The `<expression>` is evaluated at build time with the keys from `variables` available as identifiers.
41
- - You can write literally **ANY** js expression in it, because it is evaluated as an IIFE(Immediately Invoked Function Expression).
42
- - Only `#if` and `#endif` are supported(for now). `#else` / `#elif` will be supported in future releases.
50
+ - You can write **literally ANY JavaScript expressions** in it, because it is evaluated as an IIFE (Immediately Invoked Function Expression).
51
+ - Supported directives: `#if`, `#else`, `#elif`, `#endif` (similar to C/C++ style conditional compilation).
52
+ - Since it is `if/else` , it follows the syntax of `if/else` statements
43
53
 
44
54
  ### Example
45
55
 
46
- Source:
56
+ Remove testing methods in your class when compiling for production:
47
57
 
48
- ```js
49
- // #if DEBUG
50
- console.log('debug');
51
- // #endif
52
- console.log('always');
58
+ ```typescript
59
+ class User {
60
+ private name: string;
61
+ private identifier: string;
62
+
63
+ // #if DEBUG
64
+ // This method will be removed in production build
65
+ _getTestData() {
66
+ return SomeImportantDataForTesting;
67
+ }
68
+ // #endif
69
+ }
53
70
  ```
54
71
 
55
72
  If `variables.DEBUG === false`, compiled output becomes: