@@appversion ...">

Grunt and angleularJS: prod replacement

In my angularJS app I have a line like this:

<span class="build-version">@@appversion</span>

      

and a task like this in Grunt:

replace: {
  dist: {
    options: {
      patterns: [
        {
          match: '@@appversion',
          replacement: grunt.option('build-version')?grunt.option('build-version'):'#debug'
        }
      ],
      usePrefix: false
    },
    files: [
      {expand: true, flatten: true, src: ['<%= yeoman.dist %>/index.html'], dest: '<%= yeoman.dist %>'},
      {expand: true, flatten: true, src: ['<%= yeoman.dist %>/scripts/scripts.js'], dest: '<%= yeoman.dist %>/scripts'}
    ]
  }
}

      

by product. server files are copied from dev only. server (they also have a different domain name) ...

is it real and how not to replace the build version on the prod server, for example according to the domain name, url, etc ...

just what I have in mind is this code:

<span class="build-version" ng-hide="location.path().indexOf('prodserv') > -1">@@appversion</span>

      

but maybe there are better ways to do it?

+3


source to share


1 answer


I would depend on the product version (production, development) from the server variable, not the domain (or anything client based). This way you don't even need any changes to the server side code, it just expects to have a server variable that tells it what version it is and passes that information to your angular app with an ajax request when your app loads.



If you prefer to have it in the client, perhaps having a config.json file that contains the correct version might be a better idea than just guessing according to the url.

0


source







All Articles