How to run grunt server in dist directory instead of app directory?

user883807 picture user883807 · Aug 20, 2013 · Viewed 36.6k times · Source

After grunt building my AngularJS app to my dist directory, I would like to test it out with grunt server. Problem is that grunt server just serves up all the code in my app/ directory. Additionally, keep in mind that I created my app with yo angular.

Here is the server task code in my Gruntfile.js

grunt.registerTask('server', [
    'clean:server',
    'coffee:dist',
    'compass:server',
    'livereload-start',
    'connect:livereload',
    'open',
    'watch'
  ]);

Is there a way to make grunt server only serve up the built code in my dist/ directory?

Answer

Jarl picture Jarl · Jan 22, 2014

The very short answer is

grunt serve:dist

That works with my yeoman-generated Gruntfile.js which contains:

  grunt.registerTask('serve', function (target) {
    if (target === 'dist') {
      return grunt.task.run(['build', 'connect:dist:keepalive']);
    }

    grunt.task.run([
      'clean:server',
      'bower-install',
      'concurrent:server',
      'autoprefixer',
      'connect:livereload',
      'watch'
    ]);
  });