Angular5: Deploying Angular application to multiple clients

前端 未结 2 849
旧时难觅i
旧时难觅i 2020-12-03 16:07

I am developing an angular application which is a product and deployed to multiple clients. Clients will take this angular application and host it in their servers. So the S

2条回答
  •  Happy的楠姐
    2020-12-03 16:54

    For the config to be loaded initially and use it even when bootstrapping the AppModule, we used this simple solution in main.ts.

    notice we queued the

    platformBrowserDynamic().bootstrapModule(AppModule)
        .catch(err => console.error(err));
    

    inside an async function that waits for the fetching of a config file.

    (async () => {
    
      // console.time()
      const response = await fetch('./assets/config/conf.json');
      const json = await response.json();
      Object.entries(json).forEach(([key, value]) => {
        environment[key] = value;
      });
      // console.timeEnd()
    
      platformBrowserDynamic().bootstrapModule(AppModule)
        .catch(err => console.error(err));
    
    })();
    

    the config file is located in the assets and is replaced accordingly by the deployment job.

    meaning we have environment based config:

    • config.json
    • config.qa.json
    • config.prod.json

    time of fetching on for us takes about 40 milliseconds (practically nothing. uncomment the console.time to check estimations in your own projects). I doubt it will consume too much time on any project as it is fetched from a local file. good luck!

提交回复
热议问题