 module.exports = (grunt) ->
+
+  grunt.config 'env', grunt.option('env') || process.env.GRUNT_ENV || 'development'
+  isProduction = (grunt.config('env') == 'production')
 
   # Initialise the Grunt config.
   grunt.initConfig

    sass:
      theme:
        options:
          style: 'compressed'
        files:
          'theme/assets/styles.min.css.liquid': 'scss/styles.scss'

    # Optimisation of image assets.
    imagemin:

  grunt.loadNpmTasks 'grunt-newer'

  # Register tasks made available through the Gruntfile.
  if isProduction
    grunt.registerTask 'build',   ['sass', 'imagemin', 'copy']
  else
    grunt.registerTask 'build',   ['newer:sass', 'newer:imagemin', 'newer:copy']
  grunt.registerTask 'dist',    ['build', 'compress']
  grunt.registerTask 'default', ['build', 'watch']
