georoot
georoot

Reputation: 3617

Grunt build for production?

I have two grunt configurations as shown below

grunt.registerTask('default', ['copy','jade','sass','browserify']);
grunt.registerTask('dev',['copy','jade','sass','browserify','watch']);

Now because i am using grunt-contrib-watch, i need to add script below

script(src='//localhost:35729/livereload.js')

for live-reload to work. How can i optionally add the script based on production environment. Having two index.jade file is a option and that gets me through this part, but there are a lot of other variables like api root etc that depends on build environment. What is the best practice in this case to build for production and dev environment ?

Edit

Just to be sure. the above index.jade was just an example.Consider the following line in js code

RestangularProvider.setBaseUrl("http://localhost:3000");

The parameter needs to be separate for both dev and production. It would be totally illogical to have two copies of code for production and dev.

Upvotes: 3

Views: 4517

Answers (1)

Lesha Ogonkov
Lesha Ogonkov

Reputation: 1238

I prefer to use params like --build

index.jade

if env.debug
  script(src='//localhost:35729/livereload.js')

Gruntfile

module.exports = function(grunt) {
  var DEBUG = grunt.option('build') === 'dev';

  // Configure Jade to conditionally render livereload.js
  // with DEBUG === true

  grunt.initConfig({
    pug: {
      options: {
        data: function() {
          return {
            env: {
              debug: DEBUG
            }
          };
        }
      }
    }
  });
}

Use it like

grunt dev --build=dev

You can pass any env specific data via Grunt

grunt --build=dev \
      --api-endpoint=/api/foo

Upvotes: 1

Related Questions