1

I created project with ui5-cli tool. I add external js libraries to my project. ui5 serve command start ui5-server and it is maping ui5 library folder as /resource. I need to map resource/libs folder to another location in my project.

How can I configure ui5-server proxy setting for mapping/routing?

My package.json file:

{
  "name": "openui5-sample-app",
  "version": "0.2.0",
  "description": " ",
  "private": true,
  "scripts": {
    "start": "ui5 serve",
    "lint": "eslint webapp",
    "karma": "karma start",
    "karma-ci": "rimraf coverage && karma start karma-ci.conf.js",
    "watch": "npm run karma",
    "test": "npm run lint && npm run karma-ci",
    "build": "ui5 build -a --clean-dest",
    "build-self-contained": "ui5 build self-contained -a --clean-dest",
    "serve-dist": "ws --compress -d dist"
  },
  "dependencies": {
    "@openui5/sap.m": "^1.70.0",
    "@openui5/sap.ui.core": "^1.70.0",
    "@openui5/themelib_sap_fiori_3": "^1.70.0",
    "js-cookie": "^2.2.1"
  },
  "devDependencies": {
    "@ui5/cli": "^1.9.0",
    "eslint": "^5.16.0",
    "karma": "^4.3.0",
    "karma-chrome-launcher": "^3.1.0",
    "karma-coverage": "^2.0.1",
    "karma-ui5": "^1.1.0",
    "local-web-server": "^3.0.7",
    "rimraf": "^3.0.0"
  }
}

My component.js file:

jQuery.sap.registerModulePath('libs.js-cookie', '../resources/libs/js.cookie-2.2.1.min');

sap.ui.define([
     ...,
     "libs/js-cookie"
], function(UIComponent, Device, models) {
  ...
});

My yaml file:

specVersion: '1.0'
metadata:
  name: openui5-sample-app
type: application
resources:
  configuration:
    propertiesFileSourceEncoding: "UTF-8"
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
mkysoft
  • 5,392
  • 1
  • 21
  • 30

1 Answers1

0

You must update your cli to the newest version at the time or writing it is "@ui5/cli": "^1.11.1". I personally can recomend you ncu to check regulare for updates.

This config needs a CDN bootraping in your index.html.

ui5-tooling has it`s own dependencies section, add there your packages

     {
      "name": "xyz",
      "version": "1.0.0",
      "description": "xyz",
      "dependencies": {
        "@sap/approuter": "6.5.1"
      },
      "devDependencies": {
        "@ui5/cli": "^1.11.1",
        "ui5-middleware-simpleproxy": "^0.1.3",
        "ui5-tooling-livereload": "^0.1.4",
        "js-cookie": "^2.2.1"
      },
      "sapui5-runtime": {
        "version": "1.66.1"
      },
      "scripts": {

      },
      "ui5": {
        "dependencies": [
          "ui5-tooling-livereload",
          "ui5-middleware-simpleproxy",
          "js-cookie"
        ]
      }
    }

To see the great picture following the entire yaml. But you need only the things after "--- # Everything"


    specVersion: '1.0'
    metadata:
      name: my.ui5.id
    type: application
    server:
      customMiddleware:
      - name: ui5-tooling-livereload
        afterMiddleware: compression
        configuration:
          debug: true
          ext: "xml,json,properties"
          port: 35729
          path:   
            - "webapp"
      - name: ui5-middleware-simpleproxy
        mountPath: /my/local/backend/service/odata/v2
        afterMiddleware: compression
        configuration:
          baseUri: "http://localhost:8081/my/local/backend/service/odata/v2"
    --- # Everything below this line could also be put into the ui5.yaml of a standalone extension module
    specVersion: "1.0"
    kind: extension
    type: project-shim
    metadata:
      name: my.application.thirdparty
    shims:
      configurations:
        js-cookie: # name as defined in package.json
          specVersion: "1.0"
          type: module # Use module type
          metadata:
            name: js-cookie
          resources:
            configuration:
              paths:
                /resource/libs: "/src/" #here is mapped: node_modules/js-cookie/src

Benedikt Kromer
  • 711
  • 6
  • 22
  • We need to add protocol (http/https) to baseUri. I try to these configuration but sap-ui5-core.js not found. /resource mapping not working with these. I didn't make detail investigation about problem yet. – mkysoft Nov 11 '19 at 14:57
  • ah right there was a copy paste error. for /resource (openui5) you need to use "@openui5/sap.ui.core". For UI5 use a cdn in your index.html => https://sapui5.hana.ondemand.com/#/topic/2d3eb2f322ea4a82983c1c62a33ec4ae – Benedikt Kromer Nov 12 '19 at 11:21