Sovereign 8s.is mirror of standardgalactic/preprocessor-loader
  • JavaScript 68.5%
  • HTML 31.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Isaac Brown 6efb246d9b feat(meta): move to @mixer scope (#1)
* feat(meta): move to @mixer scope

* feat(meta): remove custom registry
2019-02-25 11:05:19 -08:00
demo rename 2016-12-11 00:21:08 +01:00
fixtures fixing testing 2016-11-18 14:50:34 -08:00
.editorconfig initial commit 2016-11-18 14:06:13 -08:00
.gitignore initial commit 2016-11-18 14:06:13 -08:00
.npmignore release prep 2016-12-10 22:30:07 +01:00
.travis.yml initial commit 2016-11-18 14:06:13 -08:00
index.js rename 2016-12-11 00:21:08 +01:00
LICENSE rebrand 2017-05-25 21:16:26 +02:00
package.json feat(meta): move to @mixer scope (#1) 2019-02-25 11:05:19 -08:00
readme.md rebrand 2017-05-25 21:16:26 +02:00
test.js release prep 2016-12-10 22:30:07 +01:00

preprocessor-loader

npm version Build Status

Link to preprocess documentation

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:

<h1>Hello World</h1>

<!-- @if PLATFORM == 'desktop' -->
<p>You're on our desktop build!</p>
<!-- @endif -->
<!-- @if PLATFORM == 'mobile' -->
<p>You're on our mobile build!</p>
<!-- @endif -->

The result of building the above targeting the mobile platform would be:

<h1>Hello World</h1>

<p>This is only on mobile</p>

Usage

Your webpack.config.js might look something like this:

module.exports = {
  // ...
  module: {
    loaders: [
      {
        test: /\.html$/,
        loaders: ['raw-loader', '@mcph/preprocessor-loader?_type=html&PLATFORM=' + platform]
      },
      {
        test: /\.ts$/,
        loaders: ['raw-loader', '@mcph/preprocessor-loader?_type=ts&PLATFORM=' + platform]
      },
      {
        test: /\.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.