ifdef-loader
Webpack package loader that allows JavaScript/TypeScript conditional compilation (#if ... #endif
).
Installation
In webpack build directory:
npm install ifdef-loader --save-dev
Configuration
Example of use with TypeScript files, enabling the DEBUG
and version
variables:
In webpack.config.json
:
{ test: /\.tsx?$/, exclude: /node_modules/, loaders: [ "ts-loader", 'ifdef-loader?DEBUG=true&version=3' ] }
in example.ts
:
Add ifdef-verbose
to query string if you want the loader to print informations when directives are processed:
{ test: /\.tsx?$/, exclude: /node_modules/, loaders: [ "ts-loader", 'ifdef-loader?ifdef-verbose=true' ] }
Directives
Directives must be placed after a //
doubleslash comment.
At the moment the only directive supported is #if
/#endif
(more to come).
License
MIT