Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

ant design pro 打包的问题 #24

Closed
spirobel opened this issue Apr 4, 2021 · 2 comments
Closed

ant design pro 打包的问题 #24

spirobel opened this issue Apr 4, 2021 · 2 comments

Comments

@spirobel
Copy link

spirobel commented Apr 4, 2021

你好,
我在用ant design pro boilerplate.
https://pro.ant.design/
我写了:
$ yarn create umi my-app

Select the boilerplate type: Select Ant Design Pro
❯ ant-design-pro

Which language do you want to use? Select language you use
❯ TypeScript
JavaScript

$ cd my-app
$ yarn
$ yarn start # open browser and visit http://localhost:8000
然后:
yarn add umi-plugin-electron-builder --dev
yarn electron:init
我改变antpro的targets:
{
electron: 12,
chrome: false,
firefox: false,
safari: false,
edge: false,
ios: false,
}

yarn electron:build:linux 给我这个:

umi.5d7c2ec5.js:155 Fetch API cannot load app://./api/currentUser. URL scheme "app" is not supported.
tt @ umi.5d7c2ec5.js:155
umi.5d7c2ec5.js:155 Fetch API cannot load app://./api/login/account. URL scheme "app" is not supported.

yarn electron:dev 没有问题
我找到那个:
https://gist.github.com/jarek-foksa/0f6e82bdaf8fb1962c9e14035a8725e4
改变 index.ts:

protocol.registerSchemesAsPrivileged([
  { scheme: 'app', privileges: { secure: true, standard: true, supportFetchAPI: true, } },
]);

现在可以用 fetch,
可是 fetch 不用 网络 http api

api/currentUser:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
 POST app://./api/login/account net::ERR_FILE_NOT_FOUND
POST app://./api/login/account net::ERR_FILE_NOT_FOUND
@BySlin
Copy link
Owner

BySlin commented Apr 4, 2021

在electron使用umi-request时,请指定prefix

@spirobel
Copy link
Author

spirobel commented Apr 4, 2021

在electron使用umi-request时,请指定prefix

谢谢你!
ant-design/ant-design-pro#8238

还有CORS 的问题:

Access to fetch at 'https://xxxxxx.com/api/currentUser' from origin 'app://.' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

很棒!
在 index.ts:

  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      webSecurity: false, //加这个
      contextIsolation: true,
      preload: path.join(__dirname, 'preload.js'),
    },
  });

我的 prefix 跟 yarn electron:dev 的 服务器 一样
http://localhost:8000
所以 我可以 试验 我 的 antdpro electron app 😄
很不错!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants