Electron nsis Installer x 64 不包括 node_modules?
Posted
技术标签:
【中文标题】Electron nsis Installer x 64 不包括 node_modules?【英文标题】:Electron nsis Installer x 64 not including node_modules? 【发布时间】:2018-09-12 17:44:42 【问题描述】:我有一个电子应用程序,它在开发环境和产品环境中都运行得非常顺利。 我在打包 Windows 安装程序时遇到问题。
这就是我正在做的事情。
$ npm install
-> Postinstall 将负责安装本地生产依赖项。
$ npm run prod-build
我的输出文件夹结构是:
--win-unpacked
--locales
-- resources
--app.asar.unpacked
--node_modules
**--node-datetime** ( no other node module is included)
--app
--electron
--elevate
...
--Some App Setup 1.0.0 .exe
Electron-builder 生成一个我成功安装的 .exe 文件。 应用程序启动但没有加载。知道我应该从哪里开始吗?
Package.json
"name": "Some App",
"version": "1.0.0",
"license": "MIT",
"main": "./src/app.js",
"scripts":
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build":
"productName": "Some Product",
"win":
"description": "Some Desc",
"author": "Me",
"target": "nsis",
"arch": [
"x64"
]
,
"test": "ng serve --proxy-config proxy.conf.json && electron . ",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "electron .",
"postinstall": " electron-builder install-app-deps",
"dev-build": "ng build -prod --aot=false && electron . ",
"prod-build": "ng build -prod --aot=false && electron-builder -w"
,
"private": true,
"dependencies":
"@angular/animations": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"@swimlane/ngx-charts": "^6.0.2",
"@types/jspdf": "^1.1.31",
"@types/underscore": "^1.8.3",
"bluebird": "^3.5.0",
"body-parser": "^1.18.2",
"bootstrap": "^3.3.7",
"bootstrap-notify": "^3.1.3",
"chartist": "^0.11.0",
"core-js": "^2.4.1",
"d3": "^4.10.2",
"express": "^4.16.2",
"jasmine-core": "~2.6.2",
"jquery": "^3.2.1",
"moment": "^2.21.0",
"ng2-datepicker": "^1.8.3",
"ng2-modal": "0.0.25",
"ngx-modialog": "^3.0.4",
"node-datetime": "^2.0.3",
"rxjs": "^5.1.0",
"sqlite3": "^4.0.0",
"underscore": "^1.8.3",
"zone.js": "^0.8.4"
,
"devDependencies":
"@angular/cli": "1.2.1",
"@angular/compiler-cli": "^4.0.0",
"@angular/language-service": "^4.0.0",
"@types/electron": "^1.6.10",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/jquery": "^3.2.12",
"@types/node": "~6.0.60",
"codelyzer": "~3.0.1",
"electron": "^1.8.4",
"electron-builder": "^19.45.4",
"electron-packager": "^9.1.0",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
,
将此添加到我的 package.json 的底部,而不是之前的位置
"build": "win": "target": "nsis"
app.js(入口点)
const electron = require('electron');
const express = require('express');
const e_app = express();
const bodyParser = require('body-parser');
const path = require('path')
const app = electron.app
const BrowserWindow = electron.BrowserWindow;
const url = require('url');
const fs = require('fs');
const os= require('os');
const ipc = electron.ipcMain;
const shell = electron.shell;
const router = require('./electron/routes/req-router');
const dateTime = require('node-datetime');
let win
let temp_win
//set to true for production release
function createWindow ()
win = new BrowserWindow(width:1200,height:750,webPreferences: webSecurity: false)
var serve_path = path.join('file://',__dirname,'/../build/index.html');
win.loadURL(serve_path);
win.on('closed', function ()
win = null
)
项目文件夹结构
--build
--db
--dist
--e2e
--node_modules
--src
--app
--assets
--electron
--environemtns
-app.js
-index.html
...
--typings
【问题讨论】:
【参考方案1】:安装 electron-packager 并在调用 electron-build 时引用打包的输出似乎可以解决问题。
$ npm install --save-dev electron-packager@9.1.0(恰好是我没有出错的发布版本”
添加了以下脚本
"pack": "electron-packager ."
修改了 prod-build 脚本
"prod-build": "ng build -prod --aot=false && electron-builder -w --prepackaged ./Some-App-win32-x64",
【讨论】:
以上是关于Electron nsis Installer x 64 不包括 node_modules?的主要内容,如果未能解决你的问题,请参考以下文章