Skip to content

scottmcnab/preprocess-loader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

preprocess loader module for webpack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CoffeeScript 100.0%