Skip to content

Latest commit

 

History

History
73 lines (57 loc) · 1.52 KB

README.md

File metadata and controls

73 lines (57 loc) · 1.52 KB

preprocess-loader for webpack

Webpack loader uses preprocess to preprocess HTML, Javascript, and other module files based on custom or environment configurations.

Inspired by gulp-preprocess and coffee-loader.

Usage

This loader is used within loader-chain before other loaders doing 'real' job.

var exports = require('coffee!preprocess?+DEBUG&NODE_ENV=production!./file.coffee')

Webpack Doc: Using Loaders

webpack.config file

{
  module: {
    loaders: [{
      test: /\.coffee$/
      loader: 'coffee!preprocess?+DEBUG&NODE_ENV=production'
    }]
  }
}  

Example HTML

<head>
  <title>Your App

  <!-- @if NODE_ENV='production' -->
  <script src="some/production/lib/like/analytics.js"></script>
  <!-- @endif -->

</head>
<body>
  <!-- @ifdef DEBUG -->
  <h1>Debugging mode - <!-- @echo RELEASE_TAG --> </h1>
  <!-- @endif -->
  <p>
  <!-- @include welcome_message.txt -->
  </p>
</body>

Example Javascript

var configValue = '/* @echo FOO */' || 'default value';

// @ifdef DEBUG
someDebuggingCall()
// @endif

Example Coffeescript

configValue = '/* @echo FOO */' or 'default value'
# @ifdef DEBUG
somDebuggingCall()
# @endif

More examples can be found in README of preprocess.

Licences

MIT