bier hier bier hier - 5 months ago 26
AngularJS Question

How to serve dev version of angularapp in grunt?

I am trying to serve my angular app with grunt and express. Currently the serve task looks like this:

module.exports = function(grunt) {
grunt.registerTask('serve', function(target) {

// Default task
grunt.task.run([
'clean',
// init
//'concurrent:init',
// compile html, styles, and scripts
//'concurrent:compile',

// 'uglify',
// 'Karma',
'express:server',
'open:browser',
'watch'
]);

});
};


I just want to serve the angular app without any copying, minification etc. How can I do this?

Answer

A simplest way

I suggest that you use to use Browserify which is one of the simplest way to serve a JS app via Grunt. Here is an example that supposes your JS application is in an src directory with an index.html at its root :

grunfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    browserSync: {
      bsFiles: {
        src: './src/**/*'
      },
      options: {
        server: './src'
      }
    }
  });

  grunt.loadNpmTasks('grunt-browser-sync');

  grunt.registerTask('default', ['browserSync']);
};

You obviously need to install grunt-browser-sync before (npm i -D grunt-browser-sync).


With Express

If you still wish to use express because that's you'll do in production, I suggest you the grunt-express plugin, there is a complete example app using Angular, Express and Grunt here. It's 3 years old but is still working for an actual Angular + Express application.