In Angular the "webpack_public_path" or "webpack_require.p" can be defined for a project in a couple of ways:
- Set the deployUrl in the .angular-cli.json file
- Add --deployUrl "some/path" to the "ng build" command line
However, I need to be able to set this value at runtime so it comes from my assets/config.json file when the applicaiton starts. I'm thinking of something like the following, perhaps defined in my main.ts file, but nothing I have tried works:
__webpack_require__.p=window.config['deployUrl'];
Could someone tell me how to do this, any help would be greatly appreciated! Thanks!
After some further investigation it turns out that the answer posted for the question "In Webpack, how do I set the public path dynamically?" did work. When I originally tried this I couldn't get it working, but after trying again I was successful.
The only difference was that I did not create a globals.d.ts file to add the declare statement, I just added the following lines into my main.ts file:
I'm not sure if this is best practice or not...