How to start express inside an electron?

I was able to successfully launch express in an electronic application through repositories such as

https://github.com/theallmightyjohnmanning/electron-express

https://github.com/frankhale/electron-with-express

However, I was advised not to do this because of the general public GNU license that they impose. I am trying to create a commercial application that will monetize. Therefore, liscene as MIT can do, but is not sure about GNU.

Anyway, I tried to follow his procedure: https://gist.github.com/maximilian-ruppert/a446a7ee87838a62099d

But in some problems. Here is what I have done so far.

# Clone the Quick Start repository
$ git clone https://github.com/electron/electron-quick-start

# Go into the repository
$ cd electron-quick-start

# Install the dependencies and run
$ npm install && npm start

Then, to get the expression

$ express myapp
$ cd myapp

$ npm install
renamed myapp to just app

, main.js index.html - index.html

.

Windows 10.

+2
1

-

npm install --save electron

index.html, -

, -. , Webpack, html, cs js, index.html.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>QuickMap</title>
    <link href='public/css/boostrap.min.css' rel='stylesheet'>
    <link href='public/css/layout.css' rel='stylesheet'>
  </head>
  <body>
    <div id='root' />
    <script src='public/js/appBundle.js' type='text/javascript'></script>
    <script src='public/js/bootstrap.min.js' type='text/javascript'></script>
    <script src='public/js/jquery-3.1.1.min.js' type='text/javascript'></script>
  </body>
</html>

, index.html , , -i.e html, css, js . , , jQuery, .

- Electron, Webpack

Express Webpack, index.html.

, Webpack Express Electron. , index.html , , -.

Webpack, index.html.

index.html, webpack, -.

, index.html, Express

, . , , - ( Webpack) .

, Electron, , , index.html, .

main.js

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

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win

function createWindow () {
  // Create the browser window.
  win = new BrowserWindow({width: 800, height: 600})

  // and load the index.html of the app.
  win.loadURL(url.format({
    pathname: path.join(__dirname, 'index.html'),
    protocol: 'file:',
    slashes: true
  }))

  // Open the DevTools.
  win.webContents.openDevTools()

  // Emitted when the window is closed.
  win.on('closed', () => {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    win = null
  })
}

// 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 macOS 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 macOS it 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()
  }
})

// In this file you can include the rest of your app specific main process
// code. You can also put them in separate files and require them here.

index.html, , .

mainWindow.loadURL(`file://${__dirname}/index.html`)

script .json

 "scripts": {
    "start": "ENV=development electron .",
   },

,

npm start

main.js .

+2

Source: https://habr.com/ru/post/1651582/


All Articles