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

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


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'    ]);  });


Whether or not you could do it isn't important. What is important is that you should not use grunt server for this. The server task in grunt as you can see does many things that you don't need in a dist folder, as well as the fact that they will all be hard coded for your app folder.

If you just want to try out the result of the dist folder, what you should do is just cd into the dist directory and then start a simple HTTP server like the one that comes with python.

python -m SimpleHTTPServer

That should start a small server for you to try the dist directory out.


Although other have not advised doing this, I believe this is what you are looking for. I do something like this in my server.js file when using express.

if (process.env.NODE_ENV == 'production') {    app.use(express.static('/dist'));}else{    app.use(express.static('/app'));       }

Hope this helps!