4

In the scaffold generated project using yo angular fullstack I normally launch the app with grunt using grunt (I am not an expert on it).

Example

grunt 

grunt serve

and so on.

As far as I know I have three different environments (Development, Test, Production). Every time I need to change I have to go to the main file changing the correct line (default is Development).

How can choose one of them from terminal? I am completely sure there has to be way to do that from grunt...

I can imagine it has to be something like

grunt serve --env:prod

grunt serve --test

grunt serve development

I have tried all of them but nothing, I have been spending some time trying to figure it out this from the Gruntfile but I cannot find neither googling.

Does anyone know how to do that? Any help would be appreciated

ackuser
  • 4,526
  • 5
  • 33
  • 43

2 Answers2

1

You can start your app like this NODE_ENV=production grunt and the environment variable is only production in this execution. If you want to set the environment variable you can do

> export NODE_ENV=production
> grunt

And your environment variable will remain in production until you change it for another environment.

Kangcor
  • 1,159
  • 1
  • 16
  • 25
1

Look at serve task. There are different targets. You can set target by appending colon and target name.

Development

grunt serve

Distribution (production)

grunt serve:dist

Debug

grunt serve:debug

By setting target, Grunt will run different tasks.

serve task

grunt.registerTask('serve', function (target) {
  if (target === 'dist') {
    return grunt.task.run(['build', 'env:all', 'env:prod', 'express:prod', 'wait', 'open', 'express-keepalive']);
  }

  if (target === 'debug') {
    return grunt.task.run([
      'clean:server',
      'env:all',<% if(filters.stylus) { %>
      'injector:stylus', <% } %><% if(filters.less) { %>
      'injector:less', <% } %><% if(filters.sass) { %>
      'injector:sass', <% } %>
      'concurrent:server',
      'injector',
      'wiredep',
      'autoprefixer',
      'concurrent:debug'
    ]);
  }

  grunt.task.run([
    'clean:server',
    'env:all',<% if(filters.stylus) { %>
    'injector:stylus', <% } %><% if(filters.less) { %>
    'injector:less', <% } %><% if(filters.sass) { %>
    'injector:sass', <% } %>
    'concurrent:server',
    'injector',
    'wiredep',
    'autoprefixer',
    'express:dev',
    'wait',
    'open',
    'watch'
  ]);
});
Rene Korss
  • 4,934
  • 2
  • 31
  • 36