macro-preprocessor-loader
v0.0.3
Published
The c style macro preprocessor for webpack
Downloads
10
Maintainers
Readme
macro-preprocessor-loader
The C preprocessor or cpp is the macro preprocessor for the C and C++ computer programming languages. The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.
Installation
npm install --save-dev macro-preprocessor-loader
Usage
webpack.config.js
Put the macro-preprocessor-loader
as the last loader in the array, so it processes the code before
all others.
module: {
rules: [{
test: /\.js$/,
use: ['babel-loader', 'macro-preprocessor-loader']
}]
}
Supported directives
On your code
Use //#if expression
and //#endif
to wrap blocks of code you want to be removed if a given
prediction is false.
//#if process.env.NODE_ENV === 'DEVELOPMENT'
console.log('lorem')
console.log('ipsum')
//#endif
In the example above, the code will be removed if the enviroment variable NODE_ENV
is not
DEVELOPMENT
, removing unnecessary code from your production bundle.
The same technique can be used to prevent loading packages in the production bundle.
// #if process.env.NODE_ENV !== 'BUILD'
import reduxLogger from 'redux-logger'
// #endif