2016-11-08 3 views
0

Ich erstelle meine erste SPA in Angular und konsumiere eine SpringBoot Rest API.Wie erstelle ich einen einfachen "Build" in Angular SPA

Was ich brauche, ist einen einfachen "Build" -Prozess zu erstellen, wie Maven für Java-Projekte, damit ich verschiedene Umgebungskonstanten behandeln kann. Ist es möglich, es einfach zu machen? Ich habe sehr große Konfiguration js gesehen und dies ist ein einfaches Projekt.

Ich habe dies in meinem app.js

angular.module('app', [ 'ui.router', 'ngCookies', 'ngMessages', 'ngStorage', 'ngAnimate', 'datatables', 
     'checklist-model', 'pascalprecht.translate', 'ui.bootstrap', 'oitozero.ngSweetAlert', 'ngSanitize', 
     'angucomplete-alt', 'localytics.directives', 'angular-peity']) 
      .constant('config', { 
       appName : 'MyApp', 
       appVersion : '1.0.0', 
       apiUrl : 'http://localhost:8080/rest/v1/', 
       auth : { 
        url : 'http://localhost:8080/oauth/token', 
        clientId : 'myAppOuath2', 
        header : 'Basic c29mdGFs123456F1dGgyOlh6NnFnamhwwxx=', 
        grantType : 'password' 
       } 
      }) 
... 

Und ich will die URLs mit Wildcards wie diese automatisieren:

... 
apiUrl : '{apiUrl}', 
auth : { 
    url : '{authUrl}', 
    clientId : '{clientId}', 
    header : '{authHeader}', 
    grantType : 'password' 
} 

Dank!

+0

Auschecken Grunt-Preprocess: https://github.com/jsoverson/grunt-preprocess –

Antwort

0

Ich bin nicht mit Maven vertraut. Ich habe immer Gulp oder Grunt benutzt, um meine SPA-Apps zu erstellen.

Sie können einige config.js generieren (mit Grunt Ich benutze ngconstant Plugin):

ngconstant: { 
    options: { 
    name: 'config', 
    space: ' ', 
    dest: 'app/config.js' 
    }, 
    local: { 
    constants: { 
     ENV: 'local' 
    } 
    }, 

    dev: { 
    constants: { 
     ENV: 'dev' 
    } 
    } 
} 

zu bauen:

grunt.registerTask('build', function(target) { 
    grunt.task.run([ 
     'ngconstant:' + target 
    ]) 
}) 

$ grunt build:local

Wenn die config.js erzeugt wird, ist der nächste Schritt Fügen Sie es in Ihre App ein.js

angular.module('myApp', ['config'])

+0

Maven ist für Java-Projekte. Nichts mit JS zu tun. Sollst du mir ein Beispiel für "config.js" zeigen? –

Verwandte Themen