1

我使用ui5-cli工具创建了项目。我将外部 js 库添加到我的项目中。ui5 serve命令启动ui5-server,它正在映射 ui5 库文件夹,因为/resource.我需要将resource/libs文件夹映射到项目中的另一个位置。

如何为映射/路由配置ui5-server代理设置?

我的 package.json 文件:

{
  "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"
  }
}

我的 component.js 文件:

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

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

我的 yaml 文件:

specVersion: '1.0'
metadata:
  name: openui5-sample-app
type: application
resources:
  configuration:
    propertiesFileSourceEncoding: "UTF-8"
4

1 回答 1

0

您必须将您的 cli 更新到当时的最新版本或将其写入"@ui5/cli": "^1.11.1". 我个人可以推荐你ncu 定期检查更新。

此配置需要在您的 index.html 中进行CDN 引导。

ui5-tooling 有它自己的依赖部分,添加你的包

     {
      "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"
        ]
      }
    }

查看整个 yaml 之后的精彩画面。但是你只需要“--- # 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

于 2019-11-08T08:07:09.367 回答