GithubHelp home page GithubHelp logo

byslin / umi-plugin-electron-builder Goto Github PK

View Code? Open in Web Editor NEW
153.0 6.0 25.0 856 KB

umi的electron插件

License: MIT License

TypeScript 100.00%
electron-builder umi umijs umi3 electron umi-electron umi-plugin umi4

umi-plugin-electron-builder's Introduction

umi-plugin-electron-builder

本插件提供基于umijs的electron的开发及打包,无需修改项目结构,支持混合项目结构和main+renderer项目结构,仅支持 umijs4

混合项目结构示例 点此访问

main+renderer项目结构示例 点此访问

使用混合项目结构时,插件可自动生成项目文件,使用main+renderer项目结构时,请参考示例修改目录结构

Version

更新日志

umi3请使用2.x版本插件,点此访问

安装

$ yarn add umi-plugin-electron-builder --dev

umi4需要手动启用插件

import { defineConfig } from "umi";

export default defineConfig({
  npmClient: "yarn",
  plugins: ["umi-plugin-electron-builder"],
});

配置完成之后,执行

$ yarn postinstall

执行以下指令,生成主进程文件 src/main/index.ts

$ yarn electron:init

默认安装最新版本的 electron

自动在 package.json 增加以下配置,使用@umijs/max时,请将以下命令中的umi修改为max

{
  scripts: {
    'rebuild-deps': 'electron-builder install-app-deps',
    'electron:init': 'umi electron init',
    'electron:dev': 'umi dev electron',
    'electron:build:win': 'umi build electron --win',
    'electron:build:mac': 'umi build electron --mac',
    'electron:build:linux': 'umi build electron --linux',
  },
  //这里需要修改成你自己的应用名称
  name: 'electron_builder_app',
  version: '0.0.1',
}

Electron 版本降级

你可以手动将 package.json 中的 electron 修改至低版本,插件与 electron 版本无关

开发

$ yarn electron:dev

调试主进程(VS Code)

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node-terminal",
      "request": "launch",
      "name": "debug electron:dev",
      "command": "yarn electron:dev",
      "skipFiles": [
        "<node_internals>/**"
      ],
      "sourceMapPathOverrides": {
        "webpack://main/./*": "${workspaceFolder}/src/main/*"
      },
      "resolveSourceMapLocations": [
        "${workspaceFolder}/src/.umi/electron/**",
        "${workspaceFolder}/src/renderer/.umi/electron/**"
      ],
      "autoAttachChildProcesses": true
    }
  ]
}

打包

打包路径不能有中文,electron-builder不能跨平台打包,请在对应系统上打包

//windows
$ umi build electron --win
//mac
$ umi build electron --mac
//linux
$ umi build electron --linux
//按平台打包
$ umi build electron --win --ia32    //32位
$ umi build electron --win --x64     //64位
$ umi build electron --win --armv7l  //arm32位
$ umi build electron --win --arm64   //arm64位

使用 node 环境下运行的模块

例:使用 serialport 插件

$ yarn add serialport @types/serialport

配置 .umirc.ts

import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
import { defineConfig } from 'umi';
import { InlineConfig } from 'vite';

export default defineConfig({
  electronBuilder: {
    //可选参数
    buildType: 'vite', //webpack或vite,当编译出现问题,可尝试切换为webpack
    //并行构建,默认关闭,如开启出现问题,请关闭此功能
    parallelBuild: false, //并行构建,开启时主进程和渲染进程同时编译
    mainSrc: 'src/main', //默认主进程目录
    preloadSrc: 'src/preload', //默认preload目录,可选,不需要可删除
    routerMode: 'hash', //路由 hash或memory,仅electron下有效,推荐使用hash
    outputDir: 'dist_electron', //默认打包目录
    externals: ['serialport'], //node原生模块配置,打包之后找不到包也需要配置在这里
    rendererTarget: 'web', //构建目标electron-renderer或web,使用上下文隔离时,必须设置为web
    debugPort: 5858, //主进程调试端口
    //2.1.0新增
    preloadEntry: {
      //默认值 key为preload文件名 值为preload输出文件名
      //输出文件名不能为main.js会和主进程文件名冲突
      //文件名为preload目录下多文件名
      //多级目录时key为xxxx/xxxx.ts
      //使用时输出文件会和主进程在同一目录下 preload: path.join(__dirname, 'preload.js')
      'index.ts': 'preload.js',
    },
    viteConfig(config: InlineConfig, type: "main" | "preload") {
      //主进程Vite配置
      //配置参考 https://vitejs.dev/config/
      //ConfigType分为main和preload可分别配置
    },
    //通过 webpack-chain 的 API 修改 webpack 配置。
    mainWebpackChain(config: Config, type: "main" | "preload") {
      //ConfigType分为main和preload可分别配置
      // if (type === 'main') {}
      // if (type === 'preload') {}
    },
    //2.1.10新增 开启自定义主进程日志时
    logProcess(log: string, type: "normal" | "error") {
      if (type === 'normal') {
        console.log(log);
      } else if (type === 'error') {
        console.error(log);
      }
    },
    builderOptions: {
      //配置参考 https://www.electron.build/configuration/configuration
      appId: 'com.test.test',
      productName: '测试',
      publish: [
        {
          provider: 'generic',
          url: 'http://localhost/test',
        },
      ],
    }, //electronBuilder参数
  },
  routes: [{ path: '/', component: '@/pages/index' }],
});

在 Electron10 以上使用contextIsolation时 rendererTarget 需要设置成 web

builderOptions参考 Electron Builder

已知问题

esbuild 暂不支持 typescript decorator metadata

Vite 与 typeorm 冲突,typeorm 在主进程无法使用

相关 Issue evanw/esbuild#257

umi-plugin-electron-builder's People

Contributors

byslin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

umi-plugin-electron-builder's Issues

Unable to determine a suitable edition

INFO build main process
INFO build main process success
INFO build electron
  • electron-builder  version=22.10.5 os=5.10.34-1-MANJARO
  • author is missed in the package.json  appPackageFile=/home/caocong/workspace/antproele/dist_electron/bundled/package.json
  • writing effective config  file=dist_electron/builder-effective-config.yaml
  • packaging       platform=linux arch=x64 electron=12.0.8 appOutDir=dist_electron/linux-unpacked
  • Unpacking electron zip  zipPath=undefined

/home/caocong/workspace/antproele/node_modules/errlop/edition-es5/index.js:61
                _this = _super.call(this, input.message || input) || this
                 ^
Error: editions-autoloader-none-broadened: Unable to determine a suitable edition, even after broadening.
    at new Errlop (/home/caocong/workspace/antproele/node_modules/errlop/edition-es5/index.js:61:18)
    at Object.errtion (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/util.js:23:14)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:317:21)
    at solicitEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:350:16)
    at Object.requirePackage (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:364:9)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/istextorbinary/index.cjs:4:38)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/util.js:135:22)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/sign.js:11:14)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
↳ Error: editions-autoloader-none-suitable: Unable to determine a suitable edition, as none were suitable.
    at new Errlop (/home/caocong/workspace/antproele/node_modules/errlop/edition-es5/index.js:61:18)
    at Object.errtion (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/util.js:23:14)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:327:19)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:312:12)
    at solicitEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:350:16)
    at Object.requirePackage (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:364:9)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/istextorbinary/index.cjs:4:38)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/util.js:135:22)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/sign.js:11:14)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
↳ Error: editions-autoloader-edition-incompatible: editions-autoloader-edition-incompatible: The edition [TypeScript source code made to be compatible with Deno] is not compatible with this environment.
    at new Errlop (/home/caocong/workspace/antproele/node_modules/errlop/edition-es5/index.js:61:18)
    at Object.errtion (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/util.js:23:14)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:301:25)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:312:12)
    at solicitEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:350:16)
    at Object.requirePackage (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:364:9)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/istextorbinary/index.cjs:4:38)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/util.js:135:22)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/sign.js:11:14)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
↳ Error: editions-autoloader-edition-incompatible: editions-autoloader-edition-incompatible: The edition [TypeScript compiled against ES2019 for Node.js 12 || 14 || 15 with Import for modules] is not compatible with this environment.
    at new Errlop (/home/caocong/workspace/antproele/node_modules/errlop/edition-es5/index.js:61:18)
    at Object.errtion (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/util.js:23:14)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:301:25)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:312:12)
    at solicitEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:350:16)
    at Object.requirePackage (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:364:9)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/istextorbinary/index.cjs:4:38)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/util.js:135:22)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/sign.js:11:14)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
↳ Error: editions-autoloader-edition-incompatible: editions-autoloader-edition-incompatible: The edition [TypeScript compiled against ES2019 for Node.js 10 || 12 || 14 || 15 with Require for modules] is not compatible with this environment.
    at new Errlop (/home/caocong/workspace/antproele/node_modules/errlop/edition-es5/index.js:61:18)
    at Object.errtion (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/util.js:23:14)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:301:25)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:312:12)
    at solicitEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:350:16)
    at Object.requirePackage (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:364:9)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/istextorbinary/index.cjs:4:38)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/util.js:135:22)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/sign.js:11:14)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
↳ Error: editions-autoloader-edition-incompatible: editions-autoloader-edition-incompatible: The edition [TypeScript compiled against ESNext for Node.js 14 || 15 with Require for modules] is not compatible with this environment.
    at new Errlop (/home/caocong/workspace/antproele/node_modules/errlop/edition-es5/index.js:61:18)
    at Object.errtion (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/util.js:23:14)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:301:25)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:312:12)
    at solicitEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:350:16)
    at Object.requirePackage (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:364:9)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/istextorbinary/index.cjs:4:38)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/util.js:135:22)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/sign.js:11:14)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
↳ Error: editions-autoloader-edition-incompatible: editions-autoloader-edition-incompatible: The edition [TypeScript compiled against ES2019 for web browsers with Import for modules] is not compatible with this environment.
    at new Errlop (/home/caocong/workspace/antproele/node_modules/errlop/edition-es5/index.js:61:18)
    at Object.errtion (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/util.js:23:14)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:301:25)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:312:12)
    at solicitEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:350:16)
    at Object.requirePackage (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:364:9)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/istextorbinary/index.cjs:4:38)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/util.js:135:22)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/sign.js:11:14)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
↳ Error: editions-autoloader-edition-incompatible: The edition [TypeScript source code with Import for modules] is not compatible with this environment.
    at new Errlop (/home/caocong/workspace/antproele/node_modules/errlop/edition-es5/index.js:61:18)
    at Object.errtion (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/util.js:23:14)
    at isCompatibleEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:252:19)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:287:4)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:312:12)
    at solicitEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:350:16)
    at Object.requirePackage (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:364:9)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/istextorbinary/index.cjs:4:38)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/util.js:135:22)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/sign.js:11:14)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
↳ Error: editions-autoloader-invalid-engines: The edition had no engines to compare against the environment
    at new Errlop (/home/caocong/workspace/antproele/node_modules/errlop/edition-es5/index.js:61:18)
    at Object.errtion (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/util.js:23:14)
    at isCompatibleEngines (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:183:19)
    at isCompatibleEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:250:10)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:287:4)
    at determineEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:312:12)
    at solicitEdition (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:350:16)
    at Object.requirePackage (/home/caocong/workspace/antproele/node_modules/editions/edition-es5/index.js:364:9)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/istextorbinary/index.cjs:4:38)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/util.js:135:22)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Object.newLoader [as .js] (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129144:7)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/caocong/workspace/antproele/node_modules/app-builder-lib/electron-osx-sign/sign.js:11:14)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._compile (/home/caocong/workspace/antproele/node_modules/@umijs/deps/compiled/babel/bundle.js:129139:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
error Command failed with exit code 1.

我git clone下来把electron-builder版本更新成22.11.4就正常了
可能和这串有关electron-userland/electron-builder#5668

ant design pro 打包的问题

你好,
我在用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

能否优化下目录结构?

例如现在是将 main 和其他模块拉平目录架构的,一旦业务稍微复杂点,就会变成这样:

src
├── common
├── global.less
├── hooks
├── main
├── pages
├── theme
├── tsconfig.json
└── utils

上面这样一搞,就完全不知道哪些是electron 的,哪些是浏览器的,哪些是公用的,就很容易导致认知上的偏差。

electron 里会把浏览器端叫做 renderer,pages等页面应该要放到 renderer 里面去,这样架构上才会比较合理,就像下面这样:

src
├── common
│   └── utils
├── main
│   ├── main.ts
│   └── tsconfig.json
└── renderer
    ├── global.less
    ├── hooks
    ├── pages
    ├── theme
    ├── tsconfig.json
    └── utils

能不能在插件层面做下目录架构上的优化?在简单场景下支持现在的方案,在复杂场景下支持我提的下面这种方案。

白屏

打包完会白屏???

如何使用多个preload文件

我需要使用 BrowserView 创建一个webview,需要注入自定义的方法,但是跟main进程注入的方法不一样,不想用一个preload文件,现在貌似是从preload/index.ts 直接生成了一个 preload.js 文件

mainWindow = new BrowserWindow({
    width: 1100,
    height: 800,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: true,
      preload: path.join(__dirname, 'preload.js'),  // 主进程
    },
  });


// ....................
browserView = new BrowserView({
    webPreferences: {
       contextIsolation: true,
       preload: path.join(__dirname, 'anotherPreload.js'),  //另一个渲染进程
    }
})

umi热更新babel-loader报错

操作系统
Mac OS
克隆本仓库运行示例代码

运行正常,随便编辑一处代码保存,热更新就会报错

 ERROR  Failed to compile with 1 errors                                                                                                                                                4:32:59 PM

 error  in ./src/pages/index.tsx

Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: [BABEL] /Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/src/pages/index.tsx: React Refresh Babel transform should only be enabled in development environment. Instead, the environment is: "main". If you want to override this check, pass {skipEnvCheck: true} as plugin options. (While processing: "/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/react-refresh/babel.js")
    at ReactFreshBabelPlugin (/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/react-refresh/cjs/react-refresh-babel.development.js:24:13)
    at /Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/babel-loader/node_modules/@babel/core/lib/config/full.js:211:14
    at Generator.next (<anonymous>)
    at Function.<anonymous> (/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/babel-loader/node_modules/@babel/core/lib/gensync-utils/async.js:26:3)
    at Generator.next (<anonymous>)
    at step (/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/gensync/index.js:261:32)
    at evaluateAsync (/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/gensync/index.js:291:5)
    at Function.errback (/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/gensync/index.js:113:7)
    at errback (/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/babel-loader/node_modules/@babel/core/lib/gensync-utils/async.js:70:18)
    at async (/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/gensync/index.js:188:31)
    at onFirstPause (/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/gensync/index.js:216:13)
    at Generator.next (<anonymous>)
    at cachedFunction (/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/babel-loader/node_modules/@babel/core/lib/config/caching.js:68:46)
    at cachedFunction.next (<anonymous>)
    at loadPluginDescriptor (/Users/hefx/Code/Electron/umi-plugin-electron-builder/examples/demo/node_modules/babel-loader/node_modules/@babel/core/lib/config/full.js:247:42)
    at loadPluginDescriptor.next (<anonymous>)

 @ ./src/.umi/core/routes.ts 10:17-41
 @ ./src/.umi/umi.ts
 @ multi ./node_modules/@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js ./src/.umi/umi.ts

请帮助我

无法使用 umi ui

使用 yarn create @umijs/umi-app 创建项目
使用 yarn add umi-plugin-electron-builder --dev 安装 umi-plugin-electron-builder
使用 UMI_UI=1 umi dev electron 启动项目

期望:

在无报错的情况下正常运行

真实情况:

localhost:3000 的错误如下:

TypeError: Cannot read property '_' of undefined
    at _default (/Users/jctaoo/private-work/line_bundle_checker/node_modules/umi-plugin-electron-builder/lib/index.js:39:29)
    at /Users/jctaoo/private-work/line_bundle_checker/node_modules/@umijs/core/lib/Service/Service.js:348:29
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/jctaoo/private-work/line_bundle_checker/node_modules/@umijs/core/lib/Service/Service.js:108:103)
    at _next (/Users/jctaoo/private-work/line_bundle_checker/node_modules/@umijs/core/lib/Service/Service.js:110:194)
    at /Users/jctaoo/private-work/line_bundle_checker/node_modules/@umijs/core/lib/Service/Service.js:110:364
    at new Promise (<anonymous>)
    at /Users/jctaoo/private-work/line_bundle_checker/node_modules/@umijs/core/lib/Service/Service.js:110:97
    at Service.applyAPI (/Users/jctaoo/private-work/line_bundle_checker/node_modules/@umijs/core/lib/Service/Service.js:355:7)
    at /Users/jctaoo/private-work/line_bundle_checker/node_modules/@umijs/core/lib/Service/Service.js:438:20

环境

os: macOS Catalina 10.15.6 (19G73)
yarn: 1.22.10
umi: 3.33.7

package.json

{
  "private": true,
  "scripts": {
    "start": "UMI_UI=1 umi dev",
    "build": "umi build",
    "postinstall": "umi generate tmp && electron-builder install-app-deps",
    "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
    "test": "umi-test",
    "test:coverage": "umi-test --coverage",
    "postuninstall": "electron-builder install-app-deps",
    "electron:dev": "UMI_UI=1 umi dev electron",
    "electron:build:win": "umi build electron --win",
    "electron:build:mac": "umi build electron --mac",
    "electron:build:linux": "umi build electron --linux"
  },
  "gitHooks": {
    "pre-commit": "lint-staged"
  },
  "lint-staged": {
    "*.{js,jsx,less,md,json}": [
      "prettier --write"
    ],
    "*.ts?(x)": [
      "prettier --parser=typescript --write"
    ]
  },
  "dependencies": {
    "@ant-design/pro-layout": "^6.5.0",
    "@umijs/preset-react": "1.x",
    "umi": "^3.3.7"
  },
  "devDependencies": {
    "@types/node": "^12.0.12",
    "@types/react": "^16.9.0",
    "@types/react-dom": "^16.9.0",
    "@umijs/preset-ui": "^2.2.9",
    "@umijs/test": "^3.3.7",
    "electron": "^11.2.3",
    "electron-builder": "^22.9.1",
    "electron-webpack": "^2.8.2",
    "electron-webpack-ts": "^4.0.1",
    "lint-staged": "^10.0.7",
    "prettier": "^2.2.0",
    "react": "17.x",
    "react-dom": "17.x",
    "typescript": "^4.1.2",
    "umi-plugin-electron-builder": "^1.0.1",
    "yorkie": "^2.0.0"
  },
  "electronWebpack": {
    "renderer": null
  },
  "name": "electron_builder_app",
  "version": "0.0.1",
  "main": "main.js"
}

umi执行umi dev electron后没有生成主进程文件src/main/main.ts

Error: Cannot find module './index.ts'
at webpackMissingModule (F:\Project\Front-end\React\umi-rfid\src.umi\electron\main.js:96:45)
at Object. (F:\Project\Front-end\React\umi-rfid\src.umi\electron\main.js:96:130)
at webpack_require (F:\Project\Front-end\React\umi-rfid\src.umi\electron\main.js:21:30)
at F:\Project\Front-end\React\umi-rfid\src.umi\electron\main.js:85:18
at Object. (F:\Project\Front-end\React\umi-rfid\src.umi\electron\main.js:88:10)
at Module._compile (internal/modules/cjs/loader.js:1078:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1108:10)
at Module.load (internal/modules/cjs/loader.js:935:32)
at Module._load (internal/modules/cjs/loader.js:776:14)
at Function.f._load (electron/js2c/asar_bundle.js:5:12684)

TypeError: Cannot read property 'join' of undefined

┏ Electron -------------------

(node:28291) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'join' of undefined
at createWindow (/Users/songbaoqiang/Desktop/manage-dev/src/.umi/electron/main.js:217:37)
at /Users/songbaoqiang/Desktop/manage-dev/src/.umi/electron/main.js:230:9
at step (/Users/songbaoqiang/Desktop/manage-dev/src/.umi/electron/main.js:197:23)
at Object.next (/Users/songbaoqiang/Desktop/manage-dev/src/.umi/electron/main.js:178:53)
at /Users/songbaoqiang/Desktop/manage-dev/src/.umi/electron/main.js:172:71
at new Promise ()
at module.exports../index.ts.__awaiter (/Users/songbaoqiang/Desktop/manage-dev/src/.umi/electron/main.js:168:12)
at App. (/Users/songbaoqiang/Desktop/manage-dev/src/.umi/electron/main.js:228:49)
at App.emit (events.js:315:20)
(Use Electron --trace-warnings ... to show where the warning was created)

┗ ----------------------------
┏ Electron -------------------

(node:28291) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:28291) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

┗ ----------------------------

{
"name": "ant-design-pro",
"version": "4.5.0",
"private": true,
"description": "An out-of-box UI solution for enterprise applications",
"scripts": {
"analyze": "cross-env ANALYZE=1 umi build",
"build": "umi build",
"deploy": "npm run site && npm run gh-pages",
"dev": "npm run start:dev",
"fetch:blocks": "pro fetch-blocks && npm run prettier",
"gh-pages": "gh-pages -d dist",
"i18n-remove": "pro i18n-remove --locale=zh-CN --write",
"postinstall": "umi g tmp",
"lint": "umi g tmp && npm run lint:js && npm run lint:style && npm run lint:prettier",
"lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src && npm run lint:style",
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
"lint:prettier": "prettier --check "src//*" --end-of-line auto",
"lint:style": "stylelint --fix "src/
/.less" --syntax less",
"precommit": "lint-staged",
"prettier": "prettier -c --write "src/**/
"",
"start": "cross-env REACT_APP_ENV=mock UMI_ENV=dev umi dev ",
"start:dev": "cross-env REACT_APP_ENV=dev MOCK=none UMI_ENV=dev umi dev",
"start:no-mock": "cross-env MOCK=none UMI_ENV=dev umi dev",
"start:no-ui": "cross-env UMI_UI=none UMI_ENV=dev umi dev",
"start:pre": "cross-env REACT_APP_ENV=pre UMI_ENV=dev umi dev",
"start:test": "cross-env REACT_APP_ENV=test MOCK=none UMI_ENV=dev umi dev",
"pretest": "node ./tests/beforeTest",
"test": "umi test",
"test:all": "node ./tests/run-tests.js",
"test:component": "umi test ./src/components",
"tsc": "tsc --noEmit",
"rebuild-deps": "electron-builder install-app-deps",
"electron:init": "umi electron init",
"electron:dev": "umi dev electron",
"electron:build:win": "umi build electron --win",
"electron:build:mac": "umi build electron --mac",
"electron:build:linux": "umi build electron --linux"
},
"lint-staged": {
"/*.less": "stylelint --syntax less",
"
/.{js,jsx,ts,tsx}": "npm run lint-staged:js",
"**/
.{js,jsx,tsx,ts,less,md,json}": [
"prettier --write"
]
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 10"
],
"dependencies": {
"@ant-design/charts": "^1.0.21",
"@ant-design/icons": "^4.0.0",
"@ant-design/pro-card": "^1.11.4",
"@ant-design/pro-descriptions": "^1.2.0",
"@ant-design/pro-form": "^1.3.0",
"@ant-design/pro-layout": "^6.9.0",
"@ant-design/pro-table": "^2.17.0",
"@types/serialport": "^8.0.1",
"@umijs/route-utils": "^1.0.33",
"antd": "^4.10.0",
"braft-editor": "^2.3.9",
"classnames": "^2.2.6",
"decimal.js": "^10.2.1",
"lodash": "^4.17.11",
"moment": "^2.25.3",
"omit.js": "^2.0.2",
"qs": "^6.9.0",
"react": "^17.0.0",
"react-dev-inspector": "^1.1.1",
"react-dom": "^17.0.0",
"react-helmet-async": "^1.0.4",
"serialport": "^9.0.7",
"umi": "^3.2.14",
"umi-request": "^1.0.8",
"electron-updater":"^4.3.8"
},
"devDependencies": {
"@ant-design/pro-cli": "^1.0.28",
"@types/classnames": "^2.2.7",
"@types/express": "^4.17.0",
"@types/history": "^4.7.2",
"@types/jest": "^26.0.0",
"@types/lodash": "^4.14.144",
"@types/node": "^14.6.2",
"@types/qs": "^6.5.3",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-helmet": "^6.1.0",
"@umijs/fabric": "^2.5.1",
"@umijs/plugin-blocks": "^2.0.5",
"@umijs/plugin-esbuild": "^1.0.1",
"@umijs/preset-ant-design-pro": "^1.2.0",
"@umijs/preset-react": "^1.4.8",
"@umijs/yorkie": "^2.0.3",
"carlo": "^0.9.46",
"chalk": "^4.0.0",
"cross-env": "^7.0.0",
"cross-port-killer": "^1.1.1",
"detect-installer": "^1.0.1",
"electron": "^12.0.4",
"electron-builder": "^22.10.5",
"enzyme": "^3.11.0",
"eslint": "^7.1.0",
"express": "^4.17.1",
"gh-pages": "^3.0.0",
"jsdom-global": "^3.0.2",
"lint-staged": "^10.0.0",
"mockjs": "^1.0.1-beta3",
"prettier": "^2.0.1",
"puppeteer-core": "^7.0.1",
"stylelint": "^13.0.0",
"typescript": "^4.0.3",
"umi-plugin-electron-builder": "^2.0.4"
},
"engines": {
"node": ">=10.0.0"
},
"checkFiles": [
"src//.js",
"src/
/.ts",
"src//*.less",
"config/
/.js",
"scripts/**/*.js"
]
}

有个报错求救

能否优化下模块的版本发布

希望该模块能够参考 Semantic Version 的方式进行语义化版本发布。

比如支持了双目录结构,应该发 1.1.0 吧?

且具有完整的更新日志、能够方便使用者知道更新了啥地方,判断是否应该升级模块。

不然会出现 #16 这样的报错,刚刚还挺一脸懵逼的。

ReferenceError: require is not defined

页面里使用electron包的时候提示require not defined
两种方式都报错

app.tsx

// const {dialog} = requrie('electron'); 
const {dialog} = window.requrie('electron'); 
...
export default () => {
    const handleDialogOpen = () => {
        dialog.showOpenDialog({
        ...
    })

    return (
        <>
        ...
        </>
    )
}

.umirc

export default defineConfig({
    electronBuilder: {
         buildType: 'vite',
         rendererTarget: 'electron-renderer',
         ...
    }
    ...
})

使用Mac打windows包报错,请帮忙分析一下

使用Mac机器打windows包时报错如下, 请帮忙分析一下,万分感激

INFO build main process
INFO build main process success
INFO build electron
  • electron-builder  version=22.10.5 os=20.4.0
  • writing effective config  file=dist_electron/builder-effective-config.yaml
  • packaging       platform=win32 arch=x64 electron=12.0.5 appOutDir=dist_electron/win-unpacked
  • building        target=nsis file=dist_electron/ShopCli Setup 0.0.2.exe archs=x64 oneClick=false perMachine=true
  • packager.vm is used: Cannot read property 'readFileSync' of undefined
(node:21734) UnhandledPromiseRejectionWarning: Error: Exit code: ENOENT. spawn prlctl ENOENT
    at /Users/yangchuan/developer/git/shop-cli/node_modules/umi-plugin-electron-builder/node_modules/builder-util/src/util.ts:132:18
    at exithandler (child_process.js:315:5)
    at ChildProcess.errorhandler (child_process.js:327:5)
    at ChildProcess.emit (events.js:315:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
(node:21734) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:21734) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

builderOptions 配置如下:

{
            appId: 'com.xxx.cli',
            productName: 'xxxCli',
            mac: {
                icon: 'icons/icon.png'
            },
            win: {
                icon: 'icons/icon.ico'
            },
            nsis: {
                allowElevation: false,
                allowToChangeInstallationDirectory: true,
                createDesktopShortcut: true,
                oneClick: false,
                perMachine: true
            },
            publish: [
                {
                    provider: 'generic',
                    url: 'publishUrl'                }
            ]
        }

版本信息如下:

"umi": "^3.4.11",
"umi-plugin-electron-builder": "^2.0.4",
"electron": "12.0.5",
"electron-builder": "22.10.5",

MacOS Big Sur: 11.3.1
node v14.16.1

demo引入"serialport"运行报错

已经配置nodeIntegration: true,并且umirc.ts也按照文档配置,但是demo在引入使用Serialport报错。

Error:

TypeError: Cannot read property 'modules' of undefined
(anonymous function)
./node_modules/bindings/bindings.js:27
  24 | compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled',
  25 | platform: process.platform,
  26 | arch: process.arch,
> 27 | nodePreGyp:
     | ^  28 |   'node-v' +
  29 |   process.versions.modules +
  30 |   '-' +
View compiled
./node_modules/bindings/bindings.js
http://localhost:8000/umi.js:18956:30
__webpack_require__
./webpack/bootstrap:789
  786 | };
  787 | 
  788 | // Execute the module function
> 789 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  790 | 
  791 | // Flag the module as loaded
  792 | module.l = true;
View compiled
fn
./webpack/bootstrap:100
   97 | 		);
   98 | 		hotCurrentParents = [];
   99 | 	}
> 100 | 	return __webpack_require__(request);
      | ^  101 | };
  102 | var ObjectFactory = function ObjectFactory(name) {
  103 | 	return {
View compiled

在dev下开发可以使用 cheerio , 但是打包出来无法找到 cheerio

main.ts

function createWindow() {
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
    },
  });
  if (isDevelopment) {
    mainWindow.loadURL('http://localhost:8000');
  } else {
    createProtocol('app');
    mainWindow.loadURL('app://./index.html');
  }
}

.umirc.ts

import { defineConfig } from 'umi';

export default defineConfig({
  nodeModulesTransform: {
    type: 'none',
  },
  externals: { cheerio: "window.require('cheerio')" }, //不配置的无法使用
  routes: [{ path: '/', component: '@/pages/index' }],
});

index.ts

import React, { useState } from 'react';
import styles from './index.less';
import { Button } from 'antd';
//dev下 这三个引入都可以 但是打包出来就找不到模块
const cheerio = window.require('cheerio');
// const cheerio = require('cheerio');
// import cheerio from 'cheerio';
const Index: React.FC = () => {
  const $ = cheerio.load(`<ul id="fruits">
  <li class="apple">Apple</li>
  <li class="orange">Orange</li>
  <li class="pear">Pear</li>
</ul>`);
  const [text, setText] = useState<string>('Page index');
  return (
    <div>
      <h1 className={styles.title}>{text}</h1>
      <Button
        onClick={() => {
          // const fruitsText = $('ul .pear').attr();
          const fruitsText = $('.apple').attr('id', 'favorite').html();
          setText($.html());
        }}
      >
        获取文本
      </Button>
    </div>
  );
};
export default Index;

dev下 这三个引入都可以 但是打包出来就找不到模块
const cheerio = window.require('cheerio');
const cheerio = require('cheerio');
import cheerio from 'cheerio';

main.ts没有被编译导致dev/build时失败

step:任意空目录下执行

  • yarn create @umijs/umi-app
  • yarn add umi-plugin-electron-builder --dev
  • yarn electron:dev

命令行报错

ERROR in ./src/main/main.ts 8:14
  Module parse failed: Unexpected token (8:14)
  You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
  | 
  | const isDevelopment = process.env.NODE_ENV === 'development';
  > let mainWindow: BrowserWindow;
  | 
  | protocol.registerSchemesAsPrivileged([
   @ multi ./node_modules/electron-webpack/out/electron-main-hmr/main-hmr ./src/main/main.ts main[1]

electron弹出错误窗口:
screenshot-20210225-200734

看起来像是没有把main.ts给编译到src/.umi/main/main.js,手动编译一次复制过去后正常

运行起来ForkTsCheckerWebpackPlugin会报错

环境:macOS

....
....

INFO start dev electron

[
  {
    keyword: 'additionalProperties',
    dataPath: '',
    schemaPath: '#/additionalProperties',
    params: { additionalProperty: 'tsconfig' },
    message: 'should NOT have additional properties'
  },
  {
    keyword: 'additionalProperties',
    dataPath: '',
    schemaPath: '#/additionalProperties',
    params: { additionalProperty: 'vue' },
    message: 'should NOT have additional properties'
  }
]
ValidationError: ForkTsCheckerWebpackPlugin Invalid Options

options should NOT have additional properties
options should NOT have additional properties

另外 main.ts中 installExtension 也会有问题,应该是升级到electron9导致的

(node:46202) ExtensionLoadWarning: Warnings loading extension at /Users/xxx/Library/Application Support/Electron/extensions/fmkadmapgofadopljbjfkapdkoienihi: Unrecognized manifest key 'browser_action'. Unrecognized manifest key 'minimum_chrome_version'. Unrecognized manifest key 'update_url'. Cannot load extension with file or directory name _metadata. Filenames starting with "_" are reserved for use by the system.

see electron/electron#23662

工具栏

在win上配置后运行,在工具栏没有出现Redux DevTools和React Developer Tool 但在mac上配置后运行是有的
在win上提示:
Download the React DevTools for a better development experience: https://fb.me/react-devtools

执行umi electron init之后生成了src/main/index.ts,但是执行umi dev electron之后仍然报错找不到./index.ts。

执行umi dev electron报错:
┏ Electron -------------------

App threw an error during load

┗ ----------------------------
┏ Electron -------------------

Error: Cannot find module './index.ts'
at webpackMissingModule (F:\Project\Front-end\React\umi-rfid\src.umi\electron\main.js:96:45)
at Object. (F:\Project\Front-end\React\umi-rfid\src.umi\electron\main.js:96:130)
at webpack_require (F:\Project\Front-end\React\umi-rfid\src.umi\electron\main.js:21:30)
at F:\Project\Front-end\React\umi-rfid\src.umi\electron\main.js:85:18
at Object. (F:\Project\Front-end\React\umi-rfid\src.umi\electron\main.js:88:10)
at Module._compile (internal/modules/cjs/loader.js:1078:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1108:10)
at Module.load (internal/modules/cjs/loader.js:935:32)
at Function.f._load (electron/js2c/asar_bundle.js:5:12684)

┗ ----------------------------

执行umi build electron --win下载一直卡在下面这里:
downloading url=https://github.com/electron/electron/releases/download/v12.0.2/electron-v12.0.2-win32-x64.zip size=83 MB parts=8
我把url贴到edge浏览器能下载,chrome不能下载,是我网络的什么原因吗?

1.0.16 报错

1.0.15 版本在双目录架构下可正常使用。
1.0.16 版本会报错。

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.