小编aab*_*leh的帖子

加载字体时出现 Webpack 5 错误“未捕获错误:模块解析失败:意外字符‘@’”

添加sass-loaderwebpack 配置后,使用此节点模块@fontsource/roboto时出现构建错误

import "@fontsource/roboto"; // this is in index.tsx
Run Code Online (Sandbox Code Playgroud)
Uncaught Error: Module parse failed: Unexpected character '@' (2:0)
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
| /* roboto-cyrillic-ext-400-normal*/
> @font-face {
|   font-family: 'Roboto';
|   font-style: normal;
    at eval (index.css:1)
    at Object../node_modules/@fontsource/roboto/index.css (index.js:18)
    at __webpack_require__ (index.js:556)
    at fn (index.js:767)
    at eval (index.tsx:6)
    at Module../src/index.tsx (index.js:62)
    at __webpack_require__ (index.js:556)
    at index.js:1613 …
Run Code Online (Sandbox Code Playgroud)

sass webfonts font-face webpack sass-loader

6
推荐指数
1
解决办法
1万
查看次数

如何检测 Web 应用程序是否正在 Electron 中运行

我正在尝试在电子应用程序上提供真正的反应应用程序。这并不意味着我正在使用 React 开发电子应用程序。我创建了一个反应应用程序并将其注入到电子应用程序中。(与 Slack 一样,它将充当 Web 应用程序和桌面应用程序。)但我对发送桌面通知感到困惑。

现在的主要问题是:如何获取应用程序类型。我的意思是,用户是在网络上还是在桌面上使用我的应用程序。我怎样才能得到这个?

谢谢 :)

desktop-application web reactjs electron

5
推荐指数
1
解决办法
2733
查看次数

如何声明一个只接受两个或零个参数的函数?

在 TypeScript 中,如果我声明一个这样的函数

function foo(arg1?: any, arg2?: any)
Run Code Online (Sandbox Code Playgroud)

那么如果我用以下命令调用该函数,编译器就不会抱怨

  • 零参数
  • 一个论点
  • 两个论点

如果我希望编译器遵守一个参数而不是两个或零个参数,我应该如何声明该函数?

typescript

3
推荐指数
1
解决办法
1378
查看次数

无法在渲染器进程中使用 Node.js API

无法在电子中使用任何电子或节点相关的操作。获取错误过程未定义。我检查了他们指导添加节点支持的各个地方,但这已经完成了,所以我的主要应用程序代码是

const electron = require("electron");
const { app, BrowserWindow } = electron;

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: { nodeIntegration: true },
  });

  win.loadFile("index.html");
}

app.whenReady().then(createWindow);

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});

app.on("activate", () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});
Run Code Online (Sandbox Code Playgroud)

和 Index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello World!</title>
  </head>
  <body style="background: white">
    <h1>Hello World!</h1>
    <p>
      We are using node
      <script> …
Run Code Online (Sandbox Code Playgroud)

javascript node.js electron

3
推荐指数
2
解决办法
667
查看次数

如何使用 preload.js 将 ipcRenderer.invoke 处理程序答案传递给电子渲染器进程

我正在编写一个 CRA + Electron 应用程序,我需要使用 ipcRenderer.invoke 进行进程间通信。我能够使 ipcRenderer.send 和 ipcRender.on 在 contextIsolation 模式下工作,但 ipcRender.invoke 却没有成功。由于某种我不明白的原因,我无法以任何形式(承诺或值)将处理程序响应返回给渲染器,我得到的只是“未定义”值。

预加载.js

const { contextBridge, ipcRenderer } = require('electron');

 // whitelist channels
const validChannels = ["toMain", "fromMain", "invokeMain"]
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld(
    "apiKey", {
        sendApi: (channel, ...args) => {
            if (validChannels.includes(channel)) {
                ipcRenderer.send(channel, ...args);
            }
        },
        onApi: (channel, func) => {
            if (validChannels.includes(channel)) {
                // Deliberately strip event in func …
Run Code Online (Sandbox Code Playgroud)

preload preloadjs electron ipcrenderer

1
推荐指数
1
解决办法
7109
查看次数