{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/templating/issues/589","repository_url":"https://api.github.com/repos/aspnet/templating","labels_url":"https://api.github.com/repos/aspnet/templating/issues/589/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/templating/issues/589/comments","events_url":"https://api.github.com/repos/aspnet/templating/issues/589/events","html_url":"https://github.com/aspnet/templating/issues/589","id":335851041,"node_id":"MDU6SXNzdWUzMzU4NTEwNDE=","number":589,"title":"Share variables between Dotnet and React when publishing","user":{"login":"frystpingvin","id":2557874,"node_id":"MDQ6VXNlcjI1NTc4NzQ=","avatar_url":"https://avatars3.githubusercontent.com/u/2557874?v=4","gravatar_id":"","url":"https://api.github.com/users/frystpingvin","html_url":"https://github.com/frystpingvin","followers_url":"https://api.github.com/users/frystpingvin/followers","following_url":"https://api.github.com/users/frystpingvin/following{/other_user}","gists_url":"https://api.github.com/users/frystpingvin/gists{/gist_id}","starred_url":"https://api.github.com/users/frystpingvin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frystpingvin/subscriptions","organizations_url":"https://api.github.com/users/frystpingvin/orgs","repos_url":"https://api.github.com/users/frystpingvin/repos","events_url":"https://api.github.com/users/frystpingvin/events{/privacy}","received_events_url":"https://api.github.com/users/frystpingvin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-26T14:36:54Z","updated_at":"2018-06-27T14:19:45Z","closed_at":"2018-06-27T14:19:45Z","author_association":"NONE","body":"We are building an app using the React template based on CRA. When publishing from Visual Studio, we would like to pass down an environment variable to React.\r\n\r\nWhen publishing to staging, we would to have another api url than when we publish to production. Does anyone know how we can accomplish this? We would prefer to not eject from CRA and expose the Webpack configs."},"comment":{"url":"https://api.github.com/repos/aspnet/templating/issues/comments/400688811","html_url":"https://github.com/aspnet/templating/issues/589#issuecomment-400688811","issue_url":"https://api.github.com/repos/aspnet/templating/issues/589","id":400688811,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMDY4ODgxMQ==","user":{"login":"frystpingvin","id":2557874,"node_id":"MDQ6VXNlcjI1NTc4NzQ=","avatar_url":"https://avatars3.githubusercontent.com/u/2557874?v=4","gravatar_id":"","url":"https://api.github.com/users/frystpingvin","html_url":"https://github.com/frystpingvin","followers_url":"https://api.github.com/users/frystpingvin/followers","following_url":"https://api.github.com/users/frystpingvin/following{/other_user}","gists_url":"https://api.github.com/users/frystpingvin/gists{/gist_id}","starred_url":"https://api.github.com/users/frystpingvin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frystpingvin/subscriptions","organizations_url":"https://api.github.com/users/frystpingvin/orgs","repos_url":"https://api.github.com/users/frystpingvin/repos","events_url":"https://api.github.com/users/frystpingvin/events{/privacy}","received_events_url":"https://api.github.com/users/frystpingvin/received_events","type":"User","site_admin":false},"created_at":"2018-06-27T14:19:45Z","updated_at":"2018-06-27T14:19:45Z","author_association":"NONE","body":"We achieved something good enough by adding a REACT_APP_DIST_ENV variable to our npm build scripts:\r\n```\r\n\"build\": \"npm-run-all build-css build-js\",\r\n\"build:staging\": \"cross-env REACT_APP_DIST_ENV=staging npm run build\",\r\n\"build:production\": \"cross-env REACT_APP_DIST_ENV=production npm run build\",\r\n```\r\n\r\nAnd in our .csproj file we run the correct npm script depending on configuration:\r\n```\r\n<Exec Condition=\" '$(Configuration)' == 'Debug' \" WorkingDirectory=\"$(SpaRoot)\" Command=\"npm run build:staging\" />\r\n<Exec Condition=\" '$(Configuration)' == 'Release' \" WorkingDirectory=\"$(SpaRoot)\" Command=\"npm run build:production\" />\r\n```\r\n\r\nIn our React-app we can then define variables depending on the REACT_APP_DIST_ENV variable. Of course one could add more REACT_APP-* variables if one wants to."}}
{"actor":{"display_login":"frystpingvin"}}