Title: Enviornment.ts toggling and correct usage of WebpackDevMiddlewareOptions EnvironmentVariables · Issue #1322 · aspnet/JavaScriptServices · GitHub
Open Graph Title: Enviornment.ts toggling and correct usage of WebpackDevMiddlewareOptions EnvironmentVariables · Issue #1322 · aspnet/JavaScriptServices
X Title: Enviornment.ts toggling and correct usage of WebpackDevMiddlewareOptions EnvironmentVariables · Issue #1322 · aspnet/JavaScriptServices
Description: I have added a parameter to my webpack commands so that I can swap out the Remote API endpoints. I am flipping between mocked data files and staging endpoints, and I wanted people on the team to be able to do that locally while developin...
Open Graph Description: I have added a parameter to my webpack commands so that I can swap out the Remote API endpoints. I am flipping between mocked data files and staging endpoints, and I wanted people on the team to be...
X Description: I have added a parameter to my webpack commands so that I can swap out the Remote API endpoints. I am flipping between mocked data files and staging endpoints, and I wanted people on the team to be...
Opengraph URL: https://github.com/aspnet/JavaScriptServices/issues/1322
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Enviornment.ts toggling and correct usage of WebpackDevMiddlewareOptions EnvironmentVariables","articleBody":"I have added a parameter to my webpack commands so that I can swap out the Remote API endpoints. I am flipping between mocked data files and staging endpoints, and I wanted people on the team to be able to do that locally while developing.\r\nwebpack **--env.target=staging** --progress --color\r\nwebpack **--env.target=mocked** --progress --color\r\n\r\nIn webpack I do the hostreplacement (this all seems to be worknig just fine):\r\n```\r\n const environmentFiles = {\r\n dev: \"./ClientApp/src/environments/environment.dev.ts\",\r\n devMocked: \"./ClientApp/src/environments/environment.devMocked.ts\",\r\n staging: \"./ClientApp/src/environments/environment.staging.ts\",\r\n prod: \"./ClientApp/src/environments/environment.prod.ts\"\r\n };\r\n console.log(env.target)\r\n const envFile = environmentFiles[env.target];\r\n\r\nnew AotPlugin({\r\n tsConfigPath: './tsconfig.json',\r\n entryModule: path.join(__dirname, 'ClientApp/src/app.module.browser#AppModule'),\r\n exclude: ['./**/*.server.ts'],\r\n \"hostReplacementPaths\": {\r\n \"./ClientApp/src/environments/environment\": `${envFile}`\r\n },\r\n // Set flag to false to allow AOT\r\n\t \"skipCodeGeneration\": true\r\n })\r\n```\r\n\r\nMy issue is when I run VS Code [Development] Launch Web I get a NodeServices error of target is undefined. So It does not like my env.target from the code sample above.\r\n\r\nI added the EnvironmentVariables but this does not work. I am using this wrong? I can comment out the whole UseWebpackDevMiddleware code block and let the code use the manual webpack build I created from the command line, but then I lose HMR. Which I absolutely don't want to lose. \r\n\r\n```\r\napp.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions\r\n {\r\n HotModuleReplacement = true,\r\n EnvironmentVariables = new Dictionary\u003cstring, string\u003e()\r\n {\r\n { \"target\", \"staging\" }\r\n }\r\n });\r\n```\r\n\r\nI still get the error, full error is below.\r\n\r\n```\r\nException has occurred: CLR/System.AggregateException\r\nAn exception of type 'System.AggregateException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'One or more errors occurred.'\r\n Inner exceptions found, see $exception in variables window for more details.\r\n Innermost exception \t Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException : Cannot read property 'target' of undefined\r\nTypeError: Cannot read property 'target' of undefined\r\n at module.exports (c:\\Users\\v-jormc\\Source\\Repos\\Xbox.Ambassadors\\Microsoft.Ambassadors\\Microsoft.Ambassadors.Web.Client\\webpack.config.js:19:22)\r\n at createWebpackDevServer (c:\\Users\\v-jormc\\Source\\Repos\\Xbox.Ambassadors\\Microsoft.Ambassadors\\Microsoft.Ambassadors.Web.Client\\node_modules\\aspnet-webpack\\WebpackDevMiddleware.js:194:31)\r\n at createWebpackDevServer (C:\\Users\\v-jormc\\AppData\\Local\\Temp\\104gtbeg.vbc:74:50)\r\n at C:\\Users\\v-jormc\\AppData\\Local\\Temp\\2we2pffu.pst:114:19\r\n at IncomingMessage.\u003canonymous\u003e (C:\\Users\\v-jormc\\AppData\\Local\\Temp\\2we2pffu.pst:133:38)\r\n at emitNone (events.js:105:13)\r\n at IncomingMessage.emit (events.js:207:7)\r\n at endReadableNT (_stream_readable.js:1045:12)\r\n at _combinedTickCallback (internal/process/next_tick.js:138:11)\r\n at process._tickCallback (internal/process/next_tick.js:180:9)\r\n```\r\n\r\nUpdate: Is EnviornmentVariables meant to do what is being talked about in this thread in regards to the EnvParameter? Or are we still needing something else to achieve what I am trying to do?\r\nhttps://github.com/aspnet/JavaScriptServices/issues/816\r\n","author":{"url":"https://github.com/jrmcdona","@type":"Person","name":"jrmcdona"},"datePublished":"2017-10-06T14:12:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1322/JavaScriptServices/issues/1322"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:141e2f85-867a-b445-aa99-129afd589810 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE38:1AFAE0:7DE2B6:A194DA:6974FF65 |
| html-safe-nonce | 637a7be423f1ea69267c1ca2e6f14bf3d16a66d36b8e55e0003044ef76833594 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTM4OjFBRkFFMDo3REUyQjY6QTE5NERBOjY5NzRGRjY1IiwidmlzaXRvcl9pZCI6IjUzNzYwMTc0MTIzNTAzNDUwNjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1fe5b48103401bcc98a2559a85a9c7918dd8b0560181b942040db727f5b7ac8d |
| hovercard-subject-tag | issue:263460175 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/aspnet/JavaScriptServices/1322/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d9a3bffa96c3e479a960930de3bc87a54258b76a602e4041766d8113268f0cdb/aspnet/JavaScriptServices/issues/1322 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d9a3bffa96c3e479a960930de3bc87a54258b76a602e4041766d8113268f0cdb/aspnet/JavaScriptServices/issues/1322 |
| og:image:alt | I have added a parameter to my webpack commands so that I can swap out the Remote API endpoints. I am flipping between mocked data files and staging endpoints, and I wanted people on the team to be... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jrmcdona |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4a4bf5f4e28041a9d2e5c107d7d20b78b4294ba261cab243b28167c16a623a1f |
| turbo-cache-control | no-preview |
| go-import | github.com/aspnet/JavaScriptServices git https://github.com/aspnet/JavaScriptServices.git |
| octolytics-dimension-user_id | 6476660 |
| octolytics-dimension-user_login | aspnet |
| octolytics-dimension-repository_id | 45365298 |
| octolytics-dimension-repository_nwo | aspnet/JavaScriptServices |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 45365298 |
| octolytics-dimension-repository_network_root_nwo | aspnet/JavaScriptServices |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 488b30e96dfd057fbbe44c6665ccbc030b729dde |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width