text: var fs = require('fs'),
      gulp = require('gulp'),
      gutil = require('gulp-util'),
      webpack = require('webpack'),
      uglify = require('uglify-js'),
      template = require('gulp-template-compile'),
      concat = require('gulp-concat');
  
  var ENTRY       = './index.js',
      HEADER      = './lib/header.js',
      VERSION     = './lib/version.js',
      FILE        = 'wm.js',
      FILE_MIN    = 'wm.min.js',
      FILE_MAP    = 'wm.map',
      DIST        = './dist',
      WM     = DIST + '/' + FILE,
      WM_MIN = DIST + '/' + FILE_MIN,
      WM_MAP = DIST + '/' + FILE_MAP;
  
  // generate banner with today's date and correct version
  function createBanner() {
    var today = gutil.date(new Date(), 'yyyy-mm-dd'); // today, formatted as yyyy-mm-dd
    var version = require('./package.json').version;
  
    return String(fs.readFileSync(HEADER))
        .replace('@@date', today)
        .replace('@@version', version);
  }
  
  // generate a js file containing the version number
  function updateVersionFile() {
    var version = require('./package.json').version;
  
    // generate file with version number
    fs.writeFileSync(VERSION, 'module.exports = \'' + version + '\';\n' +
        '// Note: This file is automatically generated when building wm.js.\n' +
        '// Changes made in this file will be overwritten.\n');
  }
  
  var bannerPlugin = new webpack.BannerPlugin(createBanner(), {
    entryOnly: true,
    raw: true
  });
  
  var webpackConfig = {
    entry: ENTRY,
    output: {
      library: 'wm',
      libraryTarget: 'umd',
      path: DIST,
      filename: FILE
    },
    externals: [
      'crypto' // is referenced by decimal.js
    ],
    plugins: [ bannerPlugin ],
    cache: true
  };
  
  var uglifyConfig = {
    outSourceMap: FILE_MAP,
    output: {
      comments: /@license/
    }
  };
  
  // create a single instance of the compiler to allow caching
  var compiler = webpack(webpackConfig);
  
  gulp.task('bundle', function (cb) {
    // update the banner contents (has a date in it which should stay up to date)
    bannerPlugin.banner = createBanner();
  
    updateVersionFile();
  
    compiler.run(function (err, stats) {
      if (err) {
        gutil.log(err);
      }
  
      gutil.log('bundled ' + WM);
  
      cb();
    });
  });
  
  gulp.task('minify', ['bundle'], function () {
    var result = uglify.minify([WM], uglifyConfig);
  
    fs.writeFileSync(WM_MIN, result.code);
    fs.writeFileSync(WM_MAP, result.map);
  
    gutil.log('Minified ' + WM_MIN);
    gutil.log('Mapped ' + WM_MAP);
  });
  
  
  gulp.task('jst', function () {
    gulp.src('./lib/templates/**/*.html')
        .pipe(template())
        .pipe(concat('templates.js'))
        .pipe(gulp.dest('example'));
  });
  
  
  // The default task (called when you run `gulp`)
  // gulp.task('default', ['jst', 'bundle', 'minify']);
  gulp.task('default', ['jst', 'bundle']);
  
  // The watch task (to automatically rebuild when the source code changes)
  // gulp.task('watch', ['bundle', 'minify'], function () {
  //   gulp.watch(['index.js', 'lib/**/*.js'], ['bundle', 'minify']);
  // });
  
  gulp.task('watch', ['jst', 'bundle'], function () {
    gulp.watch(['index.js', 'lib/**/*.js', './lib/templates/**/*.html'], ['jst', 'bundle']);
  });