添加sass-loader到webpack 配置后,使用此节点模块@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) 我正在尝试在电子应用程序上提供真正的反应应用程序。这并不意味着我正在使用 React 开发电子应用程序。我创建了一个反应应用程序并将其注入到电子应用程序中。(与 Slack 一样,它将充当 Web 应用程序和桌面应用程序。)但我对发送桌面通知感到困惑。
现在的主要问题是:如何获取应用程序类型。我的意思是,用户是在网络上还是在桌面上使用我的应用程序。我怎样才能得到这个?
谢谢 :)
在 TypeScript 中,如果我声明一个这样的函数
function foo(arg1?: any, arg2?: any)
Run Code Online (Sandbox Code Playgroud)
那么如果我用以下命令调用该函数,编译器就不会抱怨
如果我希望编译器遵守一个参数而不是两个或零个参数,我应该如何声明该函数?
无法在电子中使用任何电子或节点相关的操作。获取错误过程未定义。我检查了他们指导添加节点支持的各个地方,但这已经完成了,所以我的主要应用程序代码是
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) 我正在编写一个 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) electron ×3
font-face ×1
ipcrenderer ×1
javascript ×1
node.js ×1
preload ×1
preloadjs ×1
reactjs ×1
sass ×1
sass-loader ×1
typescript ×1
web ×1
webfonts ×1
webpack ×1