Skip to content

PsychoSTS/webpack-preprocessor

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webpack Preprocessor

Webpack plugin for preprocessor support

This project is my first attempt at making a webpack loader and is based on the webpack-strip-block project by jballant webpack-strip-block

JS Example:

funcion foo() {
    // Multiple blocks of logical expressions
    /*#if dev*/
    let bar = 'dev';
    /*#elif stage&&test*/
    let bar = 'stage-test';
    /*#elif stage||test*/
    let bar = 'stage-or-test';
    /*#else*/
    let bar = 'prod';
    /*#endif*/

    // Unary operators
    /*#if !dev*/
    bar += '!dev';
    /*#endif*/
    
    /*#if cond1&&cond2||cond3 */ // <-- Any combination of && and || operators are now supported
    /*#endif*/

    console.log(bar);
}

HTML Example:

<!--#if dev||stage-->
<div>DEVELOPMENT VERSION</div>
<!--#endif-->

webpack.config:

module: {
    rules: [
        { // webpack-preprocessor
            loader: 'webpack-preprocessor',
            options: {
                blocks: [
                    'stage',
                    'test'
                ]
            }
        }
    ]
}

About

Webpack plugin to strip blocks of code marked by special comment tags

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%