preprocessor-loader is a webpack loader that allows conditional compilation of HTML/TS/CSS via comment 'directives'. It's essentially a very minimalistic C/C++ preprocessor language and to interoperate fully with other templating engines and build tools.
For example, you can have split styling for a "desktop" and "xbox" build:
Hello World<!-- @if PLATFORM == 'desktop' -->You're on our desktop build!<!-- @endif --><!-- @if PLATFORM == 'mobile' -->You're on our mobile build!<!-- @endif -->
The result of building the above targeting the
mobile platform would be:
Hello WorldThis is only on mobile
webpack.config.js might look something like this:
moduleexports =// ...module:loaders:test: /\.html$/loaders: 'raw-loader' '@mcph/preprocessor-loader?_type=html&PLATFORM=' + platformtest: /\.ts$/loaders: 'raw-loader' '@mcph/preprocessor-loader?_type=ts&PLATFORM=' + platformtest: /\.scss$/loaders: 'raw-loader' '@mcph/preprocessor-loader?_type=scss&PLATFORM=' + platform;
The loader can take any number of key/value pairs, with each key representing what you want to compile against, and each value representing what you want that key to be. In this case, we specified that we only want to compile
<!-- @if PLATFORM == 'mobile' --> and want everything else to be stripped out.