% npm install generator-env-config<\/code><\/pre>\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5b8c\u4e86\u5f8c\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3001\u307e\u305a\u306f\u958b\u767a\u74b0\u5883\u7528\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n
% yo env-config<\/code><\/pre>\n\u5b9f\u884c\u5f8c\u3001config\/environments\/development.json<\/code>\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n\u30a2\u30d7\u30ea\u76f4\u4e0b\u306b\u751f\u6210\u3055\u308c\u305fconfig\/enviroments<\/code>\u914d\u4e0b\u306eJSON\u30d5\u30a1\u30a4\u30eb\u3067\u3001\u5b9f\u884c\u74b0\u5883\u6bce\u306e\u8a2d\u5b9a\u5024\u3092\u7ba1\u7406\u3057\u307e\u3059\u3002(Rails\u306b\u304a\u3051\u308bconfig\/enviroments\u306e\u30a4\u30e1\u30fc\u30b8\u3067\u3059\u306d)<\/p>\n\u540c\u3058\u3088\u3046\u306b\u3001\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u7528\u3001\u672c\u756a\u7528\u306eJSON\u30d5\u30a1\u30a4\u30eb\u3082\u751f\u6210\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n
% yo env-config staging\n% yo env-config production\n\n% ll config\/environments\/\ntotal 24\ndrwxr-xr-x 5 kuninori wheel 170 8 26 21:09 .\ndrwxr-xr-x 4 kuninori wheel 136 8 26 20:50 ..\n-rw-r--r-- 1 kuninori wheel 40 8 26 20:50 development.json\n-rw-r--r-- 1 kuninori wheel 19 8 26 21:09 production.json\n-rw-r--r-- 1 kuninori wheel 19 8 26 21:09 staging.json<\/code><\/pre>\n\u4eca\u56de\u306fAPI\u306e\u63a5\u7d9aURL\u3092\u5b9f\u884c\u74b0\u5883\u6bce\u306b\u533a\u5206\u3059\u308b\u3002\u3068\u3044\u3046\u60f3\u5b9a\u306a\u306e\u3067config\/environments\/<\/code>\u914d\u4e0b\u306e\u305d\u308c\u305e\u308c\u306e\u74b0\u5883\u8a2d\u5b9aJSON\u30d5\u30a1\u30a4\u30eb\u306b\u4e0b\u8a18\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\/\/ development.json\n{\n "apiUrl": "http:\/\/localhost:9000"\n}\n\n\/\/ staging.json\n{\n "apiUrl": "http:\/\/staging.local"\n}\n\n\/\/ production.json\n{\n "apiUrl": "http:\/\/production.local"\n}<\/code><\/pre>\nAngularJS\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u751f\u6210<\/h2>\n
\u6b21\u306b\u3001env-config\u3092\u4f7f\u7528\u3057\u3066AngularJS\u4e0a\u3067\u5b9f\u884c\u74b0\u5883\u6bce\u306e\u8a2d\u5b9a\u5024\u3092\u7ba1\u7406\u3059\u308bservices.config<\/code>\u3068\u3044\u3046\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002
\n\u5148\u7a0bJSON\u30d5\u30a1\u30a4\u30eb\u306b\u8a2d\u5b9a\u3055\u308c\u305f\u305d\u308c\u305e\u308c\u306e\u74b0\u5883\u7528\u306e\u8a2d\u5b9a\u5024\u306f\u3001\u3053\u306eservices.config<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u3067\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\u307e\u305a\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n
% yo env-config:angular config<\/code><\/pre>\n\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u5f8c\u3001config\/config.js<\/code>\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u3066\u304a\u308a\u3001\u305d\u306e\u4e2d\u3067services.config<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\nservices.config<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u3001JSON\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u5185\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308bAPI\u306eURL(apiUrl)\u3092\u6271\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n'use strict';\n\nangular.module('services.config', [])\n .constant('configuration', {\n \/\/ apiUrl\u5909\u6570\u3092\u5b9a\u7fa9\u3059\u308b\n apiUrl: '@@apiUrl'\n });<\/code><\/pre>\ngrunt-replace\u306e\u5c0e\u5165\u3068\u30bf\u30b9\u30af\u306e\u5b9a\u7fa9<\/h2>\n
\u6b21\u306bGrunt\u3092\u4f7f\u7528\u3057\u305d\u308c\u305e\u308c\u306e\u74b0\u5883\u7528\u306e\u8a2d\u5b9a\u5024\u3092\u52d5\u7684\u306b\u751f\u6210\u3067\u304d\u308b\u3088\u3046\u306bgrunt-replace<\/code>\u3092npm\u3067\u5c0e\u5165\u3057\u3001\u30d3\u30eb\u30c9\u7528\u30bf\u30b9\u30af\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n\u307e\u305a\u306fgrunt-replace<\/code>\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n% npm install grunt-replace --save-dev<\/code><\/pre>\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5f8c\u3001grunt-replace<\/code>\u3092\u30ed\u30fc\u30c9\u3059\u308b\u3088\u3046\u306bGruntfile.js<\/code>\u306e\u7de8\u96c6\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\nmodule.exports = function (grunt) {\n \/\/ module.exports\u5185\u306b\u4e0b\u8a18\u8a2d\u5b9a\u3092\u8ffd\u8a18\u3059\u308b\n grunt.loadNpmTasks('grunt-replace');\n<\/code><\/pre>\n\u4f75\u305b\u3066grunt-replace<\/code>\u7528\u306e\u30bf\u30b9\u30af\u3092grunt.initConfig<\/code>\u914d\u4e0b\u306b\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n grunt.initConfig({\n replace: {\n development: {\n options: {\n patterns: [{\n json: grunt.file.readJSON('.\/config\/environments\/development.json')\n }]\n },\n files: [{\n expand: true,\n flatten: true,\n src: ['.\/config\/config.js'],\n dest: '<%= yeoman.app %>\/scripts\/services\/'\n }]\n },\n staging: {\n options: {\n patterns: [{\n json: grunt.file.readJSON('.\/config\/environments\/staging.json')\n }]\n },\n files: [{\n expand: true,\n flatten: true,\n src: ['.\/config\/config.js'],\n dest: '<%= yeoman.app %>\/scripts\/services\/'\n }]\n },\n production: {\n options: {\n patterns: [{\n json: grunt.file.readJSON('.\/config\/environments\/production.json')\n }]\n },\n files: [{\n expand: true,\n flatten: true,\n src: ['.\/config\/config.js'],\n dest: '<%= yeoman.app %>\/scripts\/services\/'\n }]\n }\n }<\/code><\/pre>\n\u30bf\u30b9\u30af\u304c\u5b9a\u7fa9\u3067\u304d\u305f\u3089\u3001\u65e9\u901f\u958b\u767a\u74b0\u5883\u7528\u306e\u30bf\u30b9\u30af\u3092\u8d70\u3089\u305b\u3066\u307f\u307e\u3057\u3087\u3046<\/p>\n
% grunt replace:development\nRunning "replace:development" (replace) task\nReplace .\/config\/config.js \u2192 app\/scripts\/services\/config.js\n\nDone, without errors.<\/code><\/pre>\n\u30bf\u30b9\u30af\u304c\u6b63\u5e38\u7d42\u4e86\u5f8c\u3001app\/scripts\/services\/config.js<\/code>\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002
\nconfig\/environments\/development.json<\/code>\u3067\u5b9a\u7fa9\u3057\u305f\u3001\u958b\u767a\u74b0\u5883\u5411\u3051\u306eAPI\u306eURL\u304c\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u306e\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n'use strict';\n\nangular.module('services.config', [])\n .constant('configuration', {\n apiUrl: 'http:\/\/localhost:9000'\n });\n<\/code><\/pre>\nAngularJS\u30a2\u30d7\u30ea\u3067services.config\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30ed\u30fc\u30c9<\/h2>\n
\u3053\u308c\u307e\u3067\u306e\u624b\u9806\u3067\u3001\u305d\u308c\u305e\u308c\u306e\u7a3c\u50cd\u74b0\u5883\u7528\u306e\u5909\u6570\u304c\u5b9a\u7fa9\u3055\u308c\u305fservices.config<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u751f\u6210\u3067\u304d\u308b\u74b0\u5883\u304c\u6574\u3063\u305f\u305f\u3081\u3001\u751f\u6210\u3055\u308c\u305fservices.config<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092AngularJS\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304b\u3089\u30ed\u30fc\u30c9\u3057\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\u307e\u305a\u306fapp\/index.html<\/code>\u3067services.config<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u7528\u306eJavaScript\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n# config.js\u3092index.html\u306b\u8ffd\u52a0\n<script src="scripts\/services\/config.js"><\/script><\/code><\/pre>\n\u6b21\u306b\u3001app\/scripts\/app.coffee<\/code>\u304b\u3089\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30ed\u30fc\u30c9\u3002<\/p>\n'use strict'\n\n###*\n # @ngdoc overview\n # @name enviromentsAppApp\n # @description\n # # enviromentsAppApp\n #\n # Main module of the application.\n###\nangular\n .module('enviromentsAppApp', [\n 'ngAnimate',\n 'ngCookies',\n 'ngResource',\n 'ngRoute',\n 'ngSanitize',\n 'ngTouch',\n \/\/ services.config\u3092\u30ed\u30fc\u30c9\u3059\u308b\u3088\u3046\u306b\u8ffd\u52a0\n 'services.config'\n ])<\/code><\/pre>\n\u3053\u308c\u3067\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u547c\u3073\u51fa\u305b\u308b\u306e\u3067\u3001\u65e9\u901f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u304b\u3089\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308bAPI\u7528\u306eURL\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n
'use strict'\n\n###*\n # @ngdoc function\n # @name enviromentsAppApp.controller:MainCtrl\n # @description\n # # MainCtrl\n # Controller of the enviromentsAppApp\n###\nangular.module('enviromentsAppApp')\n \/\/ configuration\u3092\u30bb\u30c3\u30c8\n .controller 'MainCtrl', ($scope, configuration) ->\n \/\/ configuration.apiUrl\u3067\u5b9a\u7fa9\u3057\u3066\u3044\u308bAPI\u306eURL\u3092\u30a2\u30e9\u30fc\u30c8\u8868\u793a\u3057\u3066\u307f\u308b\n alert configuration.apiUrl<\/code><\/pre>\n\u8d77\u52d5\u3057\u3066\u307f\u308b\u3068......\u3002<\/p>\n
<\/p>\n
\u5b9a\u7fa9\u3057\u3066\u3044\u308bAPI\u306eURL\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u306d\u3002<\/p>\n
\u5f8c\u306f\u3001\u5b9f\u969b\u306bS3\u3084Web\u30b5\u30fc\u30d0\u3078AngularJS\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u969b\u306b\u5b9f\u884c\u3059\u308bGrunt\u306e\u30d3\u30eb\u30c9\u51e6\u7406\u306e\u4e2d\u3067
\n grunt replace:staging<\/code>\u3084 grunt replace:production<\/code>\u3092\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u4ed5\u8fbc\u3081\u3070\u3001\u30c7\u30d7\u30ed\u30a4\u74b0\u5883\u306b\u4f75\u305b\u3066
\n\u30d5\u30ec\u30ad\u30b7\u30d6\u30eb\u306b\u74b0\u5883\u5909\u6570\u304c\u6e96\u5099\u3067\u304d\u307e\u3059\u3002<\/p>\n\u307e\u3068\u3081<\/h2>\n
\u3044\u304b\u304c\u3067\u3057\u305f\u3067\u3057\u3087\u3046\u304b\uff1f \u4eca\u56de\u6d3b\u7528\u3057\u305fgenerator-env-config<\/code>\u4ee5\u5916\u306b\u3082\u74b0\u5883\u3054\u3068\u306e\u8a2d\u5b9a\u5024\u3092\u826f\u3044\u611f\u3058\u306b\u5b9a\u7fa9\u3059\u308b\u624b\u6cd5\u306f\u6570\u591a\u304f\u3042\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u306e\u3067
\n\u3054\u6559\u793a\u3044\u305f\u3060\u3051\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n\u3067\u306f\u3067\u306f\u3001\u826f\u304dAngularJS\u30e9\u30a4\u30d5\u3092\u200e\u256d( \uff65\u3142\uff65)\u0648 \u0311\u0311<\/p>\n
\u4eca\u56de\u3054\u7d39\u4ecb\u3057\u305f\u3088\u3046\u306a\u3001AngularJS\u306a\u3069\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u6d3b\u7528\u3057\u305f\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a<\/a>\u3092\u5fa1\u5e0c\u671b\u306e\u4f01\u696d\u69d8\u306f\u3001\u662f\u975e\u304a\u6c17\u8efd\u306bMMM\u306b\u3054\u76f8\u8ac7\u4e0b\u3055\u3044\u307e\u305b\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"\u4eca\u5e74\u306e\u590f\u306f\u3001\u5bb6\u65cf\u65c5\u884c\u3067\u884c\u3063\u305f\u6d77\u3067\u306f\u3057\u3083\u304e\u904e\u304e\u3001\u6e29\u6cc9\u5bbf\u306b\u4ed8\u3044\u305f\u77ac\u9593\u306b\u75b2\u308c\u679c\u3066\u3066\u3057\u307e\u3044\u809d\u5fc3\u306e\u6e29\u6cc9\u306b\u3042\u307e\u308a\u6d78\u304b\u308c\u305a\u3001\u7fcc\u65e5\u5168\u8eab\u7b4b\u8089\u75db\u3068\u306a\u3063\u3066\u5e30\u5b85\u3057\u305f\u306e\u304c\u30cf\u30a4\u30e9\u30a4\u30c8\u3060\u3063\u305f…..\u4ee3\u8868\u306e\u56fd\u672c\u3067\u3059\u3002 Web\u30b5\u30fc\u30d3\u30b9\u3084\u30b9\u30de\u30db\u30fb\u30a2\u30d7\u30ea\u958b\u767a\u3067\u306f\u5b9f\u969b\u306b\u30b5\u30fc\u30d3\u30b9\u304c\u7a3c\u50cd\u3059\u308b\u672c\u756a\u74b0\u5883\u306e\u4ed6\u306b\u3001\u540c\u7b49\u306e\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u3084\u958b\u767a\u74b0\u5883\u3092\u30bb\u30c3\u30c8\u3067\u69cb\u7bc9\u3059\u308b\u3053\u3068\u304c\u591a\u3005\u3042\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002 \u73fe\u5728\u5f0a\u793e\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc […]<\/p>\n","protected":false},"author":2,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[30],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/123"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=123"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/123\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media\/826"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}