Пожалуйста, помогите мне:
Я использую электронный, угловой и экспресс-сервер (Sequelize, Sqlite)
Угловой / Электронный отпроект github от maxime gris:
https://github.com/maximegris/angular-electron
для моего сервера приложений (классический экспресс-сервер): в папке api: | controller | helpers | models | маршруты
/*server.js*/
import express from 'express';
import Sequelize from 'sequelize';
import {getDb} from './helpers/dbHelper';
import PirateModel from './models/pirateModel';
import TypeModel from './models/typeModel';
import PirateRouter from './routes/pirateRoutes';
import TypeRouter from './routes/typeRoutes';
const app = express();
// connecting to sqlite database
const db = getDb();
// defining a model
const Pirate = PirateModel(db);
const Type = TypeModel(db);
// syncing db to the model changes
db.sync();
// router
const pirateRouter = PirateRouter(Pirate);
const typeRouter = TypeRouter(Type);
// parse request body as json
app.use(express.json());
// using the router at /api/pirates
app.use('/api/pirates', pirateRouter);
app.use('/api/types', typeRouter);
app.listen(5000, () => console.log('App running on port 5000'));
в пакете.JSON:
{
"name": "glooglo",
"version": "1.0.0",
"description": "GlooGlo App",
"homepage": "https://www.fakesite.net/",
"author": {
"name": "FakeName",
"email": "fakeMail@fakesite.net"
},
"keywords": [
"angular",
"angular 6",
"electron",
"typescript",
"sass"
],
"main": "main.js",
"private": true,
"scripts": {
"postinstall": "electron-builder install-app-deps",
"ng": "ng",
"start": "npm-run-all -p ng:serve electron:serve",
"start:server": "babel-node ./api/server.js",
"build": "npm run electron:tsc && ng build",
"build:dev": "npm run build -- -c dev",
"build:prod": "npm run build -- -c production",
"ng:serve": "ng serve -o",
"electron:tsc": "tsc main.ts",
"electron:serve": "wait-on http-get://localhost:4200/ && npm run electron:tsc && npm run start:server && electron . --serve",
"electron:local": "npm run build:prod && npm run start:server && electron -r babel-register .",
"electron:linux": "npm run build:prod && npx electron-builder build --linux",
"electron:windows": "npm run build:prod && npx electron-builder build --windows",
"electron:mac": "npm run build:prod && npx electron-builder build --mac",
"test": "ng test",
"e2e": "ng e2e",
"rebuild": "electron-rebuild -f -w sqlite3"
},
"dependencies": {
"crypto": "^1.0.1",
"express": "^4.16.3",
"mysql2": "^1.5.3",
"save-dev": "^2.0.0",
"sequelize": "^4.37.10",
"sqlite": "^2.9.2",
"sqlite3": "^4.0.0",
"timers": "^0.1.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.6.3",
"@angular/cli": "^6.0.7",
"@angular/common": "6.0.3",
"@angular/compiler": "6.0.3",
"@angular/compiler-cli": "6.0.3",
"@angular/core": "6.0.3",
"@angular/forms": "6.0.3",
"@angular/http": "6.0.3",
"@angular/language-service": "6.0.3",
"@angular/platform-browser": "6.0.3",
"@angular/platform-browser-dynamic": "6.0.3",
"@angular/router": "6.0.3",
"@ngx-translate/core": "10.0.1",
"@ngx-translate/http-loader": "3.0.1",
"@types/jasmine": "2.8.7",
"@types/jasminewd2": "2.0.3",
"@types/node": "8.9.4",
"babel-cli": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"codelyzer": "4.2.1",
"concurrently": "^3.5.1",
"core-js": "2.5.6",
"electron": "2.0.2",
"electron-builder": "20.14.7",
"electron-rebuild": "^1.7.3",
"electron-reload": "1.2.2",
"jasmine-core": "3.1.0",
"jasmine-spec-reporter": "4.2.1",
"karma": "2.0.2",
"karma-chrome-launcher": "2.2.0",
"karma-coverage-istanbul-reporter": "2.0.0",
"karma-jasmine": "1.1.2",
"karma-jasmine-html-reporter": "1.1.0",
"npm-run-all": "4.1.3",
"npx": "10.2.0",
"protractor": "5.3.2",
"rxjs": "6.1.0",
"ts-node": "6.0.3",
"tslint": "5.10.0",
"typescript": "2.7.2",
"wait-on": "2.1.0",
"webdriver-manager": "12.0.6",
"zone.js": "0.8.26"
},
"babel": {
"presets": [
"es2015"
],
"sourceMaps": true,
"retainLines": true
}
}
В main.ts:
import { app, BrowserWindow, screen } from 'electron';
import * as path from 'path';
import * as url from 'url';
// import './api/server'; <= FOR TESTING I USE THIS
let win, serve;
const args = process.argv.slice(1);
serve = args.some(val => val === '--serve');
function createWindow() {
const electronScreen = screen;
const size = electronScreen.getPrimaryDisplay().workAreaSize;
const appPath = app.getAppPath();
// WHEN I PACKAGE THE APP I USE THIS
const serverLink = path.join(__dirname , '..' , './../api/server.js');
const runServer = require(serverLink);
// END WHEN I PACKAGE
// Create the browser window.
win = new BrowserWindow({
x: 0,
y: 0,
width: size.width,
height: size.height
});
if (serve) {
require('electron-reload')(__dirname, {
electron: require(`${__dirname}/node_modules/electron`)});
win.loadURL('http://localhost:4200');
} else {
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true
}));
}
win.webContents.openDevTools();
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
}
try {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow();
}
});
} catch (e) {
// Catch Error
// throw e;
}
В электронно-строитель.JSON:
{
"productName": "IGLOO",
"directories": {
"output": "app-builds"
},
"files": [
"**/*",
"!*.ts",
"!*.code-workspace",
"!LICENSE.md",
"!package.json",
"!package-lock.json",
"!src/",
"!e2e/",
"!hooks/",
"!.angular-cli.json",
"!_config.yml",
"!karma.conf.js",
"!tsconfig.json",
"!tslint.json"
],
"win": {
"icon": "dist",
"target": [
"portable"
]
},
"mac": {
"icon": "dist",
"target": [
"dmg"
]
},
"linux": {
"icon": "dist",
"target": [
"AppImage"
]
},
"extraFiles":[
"api",
"database"
]
}
ПРОБЛЕМА? когда я запускаю:
npm run electron:local => The App work correctly and the server too
Теперь, когда я упаковываю свое приложение с:
npm run electron:windows => I have the packaged app: Glooglo.exe (with api/database)
Когда я запускаю это приложение:
Uncaught Exception
import express from 'express'
SyntaxError: Unexpected token import
......
at App.createWindow
at \app\ressoucers\app.asar\main.js:19.20
Предустановка Babel с Es2015не работает, когда я упаковываю приложение и запускаю его