title: Automatic minification with nodeJS and Gulp task runner
body: <p>I need some advices to improve automatic minification with node and gulp.</p>
  
  <p>The main objective is generate dynamically the minified files(for JS and LESS) in development mode and change automatically normal files(js and less) to minified files in production mode.</p>
  
  <p>The scenario contains:</p>
  
  <ul>
  <li>NodeJS and ExpressJS for routing and environment configuration</li>
  <li>Jade as template engine</li>
  <li>Gulp (task runner)</li>
  </ul>
  
  <p>This is my setup:</p>
  
  <p><strong>GULP</strong></p>
  
  <p>I'm using nodemon in order to lauch server.js wich starts my node server.
  In this gulp file i have some tasks (['watch']) for watch the changes on JS and LESS files and minify them in every single change.</p>
  
  <pre><code>gulp.task('nodemon', function () {
      nodemon({ script: 'server.js'})
          .on('start', ['watch'])
          .on('change', ['watch'])
  })
  </code></pre>
  
  <p><strong>NODE</strong></p>
  
  <p>In node server I render the views injecting and object which detects the development or production mode</p>
  
  <pre><code>  var env= process.env.NODE_ENV = process.env.NODE_ENV || 'development';
  
    app.get('/', function(req, res){
          res.render('index', {environment: env});
      });
  </code></pre>
  
  <p><strong>JADE</strong></p>
  
  <p>In the view, the injected object is compared in order to add normal CSS and JS files for development mode or minified files for production mode</p>
  
  <pre><code> if environment == "development"
              link(rel='stylesheet', href='/vendor/bootstrap/dist/css/bootstrap.css')
    else
              link(rel='stylesheet', href='/vendor/bootstrap/dist/css/bootstrap.min.css')
  </code></pre>
  
  <p>Is this the correct way to do this? Should i need check for another options? I want to avoid manual minification before submit app to server every time. All advices would be accepted in order to improve this.</p>
  
  <p>Is better do minification at server lauching gulp? How i can do it with Azure?</p>
  
  <p>Thank you.</p>