2

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!

David V
  • 161
  • 3
  • 13
  • what does deployUrl do, I am bad with terminology ? – Vamshi Jun 28 '17 at 03:42
  • The deployUrl sets the public path in webpack, you can read about it at https://github.com/webpack/docs/wiki/configuration#outputpublicpath. The other thing I would mention here is that it seems that there was a documented solution to my question at https://stackoverflow.com/questions/37186218/in-webpack-how-do-i-set-the-public-path-dynamically but I have not been able to get this solution to work. – David V Jun 28 '17 at 15:58

1 Answers1

3

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:

declare var  __webpack_public_path__:string;
__webpack_public_path__= 'public/path/location';

I'm not sure if this is best practice or not...

rmlarsen
  • 177
  • 1
  • 13
David V
  • 161
  • 3
  • 13