Build next.js in electron

Need to clean this up.
This commit is contained in:
uonai 2020-07-04 11:30:32 -05:00
parent 59e8312d81
commit 5a42b9237a
6 changed files with 54 additions and 33 deletions

View File

@ -1,9 +1,16 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow } = require("electron");
const path = require("path");
const { app, BrowserWindow } = require('electron');
const path = require('path');
// (colin) this may not be needed
const prepareRenderer = require('electron-next');
// const { fork } = require("child_process");
// const ps = fork(path.join(__dirname, "..", "index.js"));
function bootServer() {
const { fork } = require('child_process');
const ps = fork(path.join(__dirname, '../', 'index.js'));
console.log('server running');
}
// require(path.join(__dirname, "../nodedistribution/", "main.js"));
function createWindow() {
// Create the browser window.
@ -11,25 +18,25 @@ function createWindow() {
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
},
});
// Open the DevTools.
mainWindow.webContents.openDevTools();
// and load the index.html of the app.
mainWindow.loadURL("http://localhost:1337");
console.log("window created");
require(path.join(__dirname, "../nodedistribution/", "main.js"));
mainWindow.loadURL('http://localhost:1337');
console.log('window created');
}
// 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.whenReady().then(() => {
bootServer();
createWindow();
app.on("activate", function () {
app.on('activate', function () {
// On macOS 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 (BrowserWindow.getAllWindows().length === 0) createWindow();
@ -39,8 +46,8 @@ app.whenReady().then(() => {
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", function () {
if (process.platform !== "darwin") app.quit();
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});
// In this file you can include the rest of your app's specific main process

View File

@ -1,6 +1,10 @@
require("@babel/register")({
presets: ["@babel/preset-env"],
ignore: ["node_modules", ".next"],
const regeneratorRuntime = require('regenerator-runtime');
require('electron-compile');
require('@babel/register')({
presets: [[require.resolve('@babel/preset-env')]],
// ignore: ['node_modules', '.next'],
});
module.exports = require("./server.js");
console.log('index.js ran');
module.exports = require('./server.js');
console.log('server.js ran');

View File

@ -1,4 +1,4 @@
import * as Constants from '../node_common/constants';
import * as Constants from 'constants';
import FS from 'fs-extra';

View File

@ -11,7 +11,7 @@
"dev": "node . --unhandled-rejections=strict",
"dev:node": "NODE_ENV=development webpack --config webpack.node.config.js --mode development",
"build": "next build",
"start": "electron ./electron/main.js",
"start": "electron .",
"electron": "electron ./electron/main.js ",
"electronPack": "electron-builder --dir",
"electronDist": "electron-builder"
@ -25,7 +25,6 @@
}
},
"dependencies": {
"@babel/preset-env": "^7.10.4",
"@babel/register": "^7.10.4",
"@emotion/babel-preset-css-prop": "^10.0.27",
"@emotion/cache": "11.0.0-next.12",
@ -39,26 +38,33 @@
"chart.js": "^2.9.3",
"chartkick": "^3.2.0",
"compression": "^1.7.4",
"core-js": "^3.6.5",
"dotenv": "^8.2.0",
"electron-compile": "^6.4.4",
"electron-next": "^3.1.5",
"express": "^4.17.1",
"formidable": "^1.2.2",
"fs-extra": "^9.0.1",
"isomorphic-fetch": "^2.2.1",
"moment": "^2.27.0",
"next": "^9.4.4",
"protobufjs-electron": "^6.8.8",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-draggable": "^4.4.3",
"react-tippy": "^1.3.4",
"regenerator-runtime": "^0.13.5",
"three": "^0.108.0",
"uuid": "^8.0.0",
"ws": "^7.3.0"
},
"devDependencies": {
"@babel/preset-env": "^7.10.4",
"@rollup/plugin-node-resolve": "^8.1.0",
"babel-loader": "^8.1.0",
"electron": "^9.0.5",
"electron-builder": "^22.7.0",
"electron-compilers": "^5.9.0",
"electron-forge": "^5.2.4",
"rollup": "^2.18.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",

View File

@ -4,7 +4,6 @@ import * as Utilities from './node_common/utilities';
import * as Constants from './node_common/constants';
import { createPow, ffs } from '@textile/powergate-client';
// NOTE(jim):
// https://github.com/textileio/js-powergate-client
const PowerGate = createPow({ host: Constants.POWERGATE_HOST });
@ -25,8 +24,16 @@ let state = null;
const production = process.env.NODE_ENV === 'production';
const port = process.env.PORT || 1337;
const wsPort = process.env.WS_PORT || 2448;
const resetData = process.env.npm_config_reset_data;
const app = next({ dev: !production, quiet: false });
const path = require('path');
const app = next({
dev: false,
dir: __dirname,
conf: {
distDir: path.resolve('./.next'),
},
quiet: false,
});
const nextRequestHandler = app.getRequestHandler();
const setIntervalViewerUpdatesUnsafe = async () => {

View File

@ -1,27 +1,24 @@
const path = require("path");
const nodeExternals = require("webpack-node-externals");
const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
resolve: {
extensions: [".js"],
extensions: ['.js'],
},
entry: "./index.js",
target: "node",
entry: './index.js',
target: 'node',
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
],
},
output: {
libraryTarget: "commonjs",
path: path.resolve(__dirname, "./nodedistribution"),
filename: "[name].js",
libraryTarget: 'commonjs',
path: path.resolve(__dirname, './nodedistribution'),
filename: '[name].js',
},
externals: [nodeExternals()],
};