2

I'm now working on sapui5 project managed by ui5.yaml & @ui5/cli. I don't know how to use something like .env to control some variables' value which can be switched between dev env and pro env.

And i have found a workaround, which creating a env.js and include it into controller file. So i can change some value by editing the env.js file. And now i want to make it more convenient.

I use @ui5/cli ui5 run build to build the project. And there is a configuration for custom tasks. And there is a task called webide-extension-task-copyFile which used to copy the /xs-app.json.

And now i create three env files which named as env-dev.js env-pro.js env.js. And i want to copy the env-pro into the env.js before it is built. And copy the env-dev into env.js when i run the ui5 run serve.

I have the config in ui5.yaml like this

specVersion: '2.4'
metadata:
  name: ui
type: application
framework:
  name: SAPUI5
....
customTasks:
....
  - name: webide-extension-task-copyFile
    afterTask: webide-extension-task-resources
    configuration:
      srcFile: '/webapp/env/env-pro.js'
      destFile: '/webapp/env/env.js'

I'm sure the task has been triggered, but the file content hasn't been changed. So could someone can help me, or has another idea or success example about using the env in ui5 project.

Thank you :)

Zou Yi
  • 21
  • 2
  • Where is it deployed? I add the production env variables directly on the running application in BTP. Other hosts will probably have similar options – Jorg Jan 17 '22 at 21:57
  • 1
    Have you tried using https://www.npmjs.com/package/ui5-task-stringreplacer? This worked for us in the past. – z00bs Jan 21 '22 at 08:45
  • ui5-task-stringreplacer, it works. Thank you! – Zou Yi Jan 09 '23 at 02:44

0 Answers0