gpt4 book ai didi

javascript - 如何在 Jhipster Angular 生成的应用程序上使用 Electron ?

转载 作者:行者123 更新时间:2023-11-30 13:49:32 25 4
gpt4 key购买 nike

我刚刚发现了 electron,我觉得它很有趣,所以我想在我的 jhipster angular 项目(最新的 jhipster 版本)上实现它

我尝试遵循本教程并对其进行调整,但我相信由于 Jhipster 使用 Webpack,我的构建并不好

这是我做的

我在 src/main/webapp 文件夹中声明了一个 ma​​in.js 文件,如下所示

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

let win;

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

// load the dist folder from Angular
win.loadURL(
url.format({
pathname: path.join(__dirname, `/dist/index.html`),
protocol: "file:",
slashes: true
})
);

// The following is optional and will open the DevTools:
// win.webContents.openDevTools()

win.on("closed", () => {
win = null;
});
}

app.on("ready", createWindow);

// on macOS, closing the window doesn't quit the app
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});

// initialize the app's main window
app.on("activate", () => {
if (win === null) {
createWindow();
}
});

然后我尝试如下更新我的配置文件

package.json

{
"name": "boxing",
"version": "0.0.1-SNAPSHOT",
"main": "main.js", <-- added this
"description": "Description for boxing",
"private": true,
"license": "UNLICENSED",
"cacheDirectories": [
"node_modules"
],
"dependencies": {
"@angular-devkit/build-angular": "^0.803.14", <-- installed using npm
...
"scripts": {
"electron": "ng build --base-href ./ && electron .",

angular.json

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"boxing": {
"root": "",
"sourceRoot": "src/main/webapp",
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"skipTests": true,
"style": "scss"
},
"@schematics/angular:directive": {
"skipTests": true
},
"@schematics/angular:guard": {
"skipTests": true
},
"@schematics/angular:pipe": {
"skipTests": true
},
"@schematics/angular:service": {
"skipTests": true
}
},
"prefix": "jhi",
"architect": {
<-- added this lines
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist"
}
}
<-- end of add
}
}
},
"defaultProject": "boxing",
"cli": {
"packageManager": "npm"
}
}

我最终将我的 index.html href 更新为 ./

但是当我在终端中运行命令时,我收到了这个错误

npm run electron

boxing@0.0.1-SNAPSHOT Electron /home/housseyn/Desktop/projects/sale-de-sport ng build --base-href ./&& electron .

架构验证失败,出现以下错误: 数据路径“”应该具有必需的属性“main”。 错误!代码生命周期 错误!错误号 1 错误! boxing@0.0.1-SNAPSHOT Electron :ng build --base-href ./&& electron . 错误!退出状态 1 错误! 错误!在 boxing@0.0.1-SNAPSHOT Electron 脚本处失败。 错误!这可能不是 npm 的问题。 >上面可能有额外的日志输出。

npm 错误!可以在以下位置找到此运行的完整日志: 错误!/home/housseyn/.npm/_logs/2019-10-25T16_00_19_675Z-debug.log

最佳答案

你必须使用这个命令构建你的项目 npm run electron-build 之后你将它添加到你的 package.json 脚本中

检查这个doc直到结束

希望对你有帮助

关于javascript - 如何在 Jhipster Angular 生成的应用程序上使用 Electron ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58562559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com