text: 
  'use strict';
  
  module.exports = function (grunt) {
  
    // Load grunt tasks automatically
    require('load-grunt-tasks')(grunt);
  
    // Configurable paths for the application
    var appConfig = {
      app: require('./bower.json').appPath || 'app',
      dist: 'dist'
    };
  
    // Define the configuration for all the tasks
    grunt.initConfig({
      // Project settings
      config: appConfig,
  
      // Watches files for changes and runs tasks based on the changed files
      watch: {
        livereload: {
          options: {
            livereload: '<%= connect.options.livereload %>'
          },
          files: [
            '<%= config.app %>/**/*.html',
            '<%= config.app %>/**/*.css',
            '<%= config.app %>/**/*.js',
            '.tmp/styles/**/*.css',
            '<%= config.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
          ]
        }
      },
  
      // The actual grunt server settings
      connect: {
        options: {
          port: 9000,
          // Change this to '0.0.0.0' to access the server from outside.
          hostname: 'localhost',
          livereload: 35729
        },
        livereload: {
          options: {
            open: true,
            middleware: function (connect) {
              return [
                connect.static('.tmp'),
                connect().use(
                  '/bower_components',
                  connect.static('./bower_components')
                ),
                connect().use(
                  '/external_components',
                   connect.static('./external_components')
                ),
                connect.static(appConfig.app)
              ];
            }
          }
        }
      },
  
      clean: {
        dist: {
          files: [{
            dot: true,
            src: [
              '.tmp',
              '<%= config.dist %>/{,*/}*',
              '!<%= config.dist %>/.git*'
            ]
          }]
        },
        server: '.tmp'
      },
  
      // Add vendor prefixed styles
      autoprefixer: {
        options: {
          browsers: ['last 5 versions']
        },
        dist: {
          files: [{
            expand: true,
            cwd: '.tmp/styles/',
            src: '**/*.css',
            dest: '.tmp/styles/'
          }]
        }
      },
  
      wiredep: {
        app: {
          src: ['<%= config.app %>/index.html'],
          ignorePath:  /\.\.\//
        }
      },
  
      // Reads HTML for usemin blocks to enable smart builds that automatically
      // concat, minify and revision files. Creates configurations in memory so
      // additional tasks can operate on them
      useminPrepare: {
        html: '<%= config.app %>/index.html',
        options: {
          dest: '<%= config.dist %>',
          flow: {
            html: {
              steps: {
                js: ['concat', 'uglifyjs'],
                css: ['cssmin']
              },
              post: {}
            }
          }
        }
      },
  
      // Performs rewrites based on filerev and the useminPrepare configuration
      usemin: {
        html: ['<%= config.dist %>/**/*.html'],
        css: ['<%= config.dist %>/styles/**/*.css'],
        options: {
          assetsDirs: ['<%= config.dist %>','<%= config.dist %>/images']
        }
      },
  
      copy: {
        dist: {
          files: [{
            expand: true,
            dot: true,
            cwd: '<%= config.app %>',
            dest: '<%= config.dist %>',
            src: [
              '*.{ico,png,txt}',
              '.htaccess',
              '*.html',
              '**/*.html',
              'images/{,*/}*.{webp}',
              'fonts/*',
              '**/i18n/*.js'
            ]
          }, {
            expand: true,
            cwd: '.tmp/images',
            dest: '<%= config.dist %>/images',
            src: ['generated/*']
          }, {
            expand: true,
            cwd: 'bower_components/bootstrap/dist',
            src: 'fonts/*',
            dest: '<%= config.dist %>'
          }, {
            expand: true,
            cwd: 'bower_components/font-awesome',
            src: 'fonts/*',
            dest: '<%= config.dist %>'
          }, {
            expand: true,
            cwd: 'app/modules',
            src: 'i18n/*',
            dest: '<%= config.dist %>/modules/'
          }
            ]
        },
        styles: {
          files: [{
            expand: true,
            cwd: '<%= config.app %>/styles',
            dest: '.tmp/styles/',
            src: '**/*.css'
          }, {
            expand: true,
            cwd: '<%= config.app %>/custom-modules',
            dest: '.tmp/styles/',
            src: '**/*.css'
          }]
        }
      },
  
      imagemin: {
        dist: {
          files: [{
            expand: true,
            cwd: '<%= config.app %>/images',
            src: '{,*/}*.{png,jpg,jpeg,gif}',
            dest: '<%= config.dist %>/images'
          }]
        }
      },
  
      svgmin: {
        dist: {
          files: [{
            expand: true,
            cwd: '<%= config.app %>/images',
            src: '{,*/}*.svg',
            dest: '<%= config.dist %>/images'
          }]
        }
      },
  
      htmlmin: {
        dist: {
          options: {
            collapseWhitespace: true,
            conservativeCollapse: true,
            collapseBooleanAttributes: true,
            removeCommentsFromCDATA: true,
            removeOptionalTags: true
          },
          files: [{
            expand: true,
            cwd: '<%= config.dist %>',
            src: ['*.html', '**/*.html'],
            dest: '<%= config.dist %>'
          }]
        }
      },
  
      // ng-annotate tries to make the code safe for minification automatically
      // by using the Angular long form for dependency injection.
      ngAnnotate: {
        dist: {
          files: [{
            expand: true,
            cwd: '.tmp/concat/scripts',
            src: ['*.js', '!oldieshim.js'],
            dest: '.tmp/concat/scripts'
          }]
        }
      },
  
      // Renames files for browser caching purposes
      filerev: {
        dist: {
          src: [
            '<%= config.dist %>/scripts/{,*/}*.js',
            '<%= config.dist %>/styles/{,*/}*.css',
            '<%= config.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
            '<%= config.dist %>/styles/fonts/*',
            '!<%= config.dist %>/images/os_email_logo.png'
          ]
        }
      },
  
      // Run some tasks in parallel to speed up the build process
      concurrent: {
        server: [
          'copy:styles'
        ],
        dist: [
          'copy:styles',
          'imagemin',
          'svgmin'
        ]
      }
    });
  
    grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
      if (target === 'dist') {
        return grunt.task.run(['build', 'connect:dist:keepalive']);
      }
  
      grunt.task.run([
        'clean:server',
        'wiredep',
        'concurrent:server',
        'autoprefixer',
        'connect:livereload',
        'watch'
      ]);
    });
  
    grunt.registerTask('build', [
      'clean:dist',
      'wiredep',
      'useminPrepare',
      'concurrent:dist',
      'autoprefixer',
      'concat',
      'ngAnnotate',
      'copy:dist',
      'cssmin',
      'uglify',
      'filerev',
      'usemin',
      'htmlmin'
    ]);
  };
  