-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address #1 by adding a build process for renderer and main
- Loading branch information
Showing
6 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,45 @@ | ||
import { app, BrowserWindow } from 'electron'; | ||
import * as path from 'path'; | ||
|
||
require('electron-reload')(__dirname); | ||
import * as url from 'url'; | ||
|
||
let mainWindow: Electron.BrowserWindow; | ||
|
||
function createWindow() { | ||
// Create the browser window. | ||
const createWindow = () => { | ||
mainWindow = new BrowserWindow({ | ||
height: 600, | ||
width: 900 | ||
}); | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
console.log('Loading development environment'); | ||
mainWindow.loadURL('http://localhost:8080'); | ||
mainWindow.webContents.openDevTools(); | ||
} else { | ||
mainWindow.loadFile(path.join(__dirname, 'index.html')); | ||
console.log('Loading non-development environment'); | ||
mainWindow.loadURL( | ||
url.format({ | ||
pathname: path.join(__dirname, 'index.html'), | ||
protocol: 'file:', | ||
slashes: true | ||
}) | ||
); | ||
} | ||
|
||
// Emitted when the window is closed. | ||
mainWindow.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. | ||
mainWindow = 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 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 (mainWindow === null) { | ||
createWindow(); | ||
} | ||
}); | ||
|
||
// In this file you can include the rest of your app"s specific main process | ||
// code. You can also put them in separate files and require them here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const path = require('path'); | ||
const merge = require('webpack-merge'); | ||
const webpack = require('webpack'); | ||
const common = require('./webpack.common.js'); | ||
const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); | ||
const WorkboxPlugin = require('workbox-webpack-plugin'); | ||
|
||
module.exports = merge(common, { | ||
mode: 'production', | ||
target: 'electron-renderer', | ||
devtool: 'source-map', | ||
output: { | ||
filename: '[name].[chunkhash].js' | ||
}, | ||
optimization: { | ||
minimize: true, | ||
nodeEnv: 'production', | ||
concatenateModules: true, | ||
splitChunks: { | ||
cacheGroups: { | ||
vendor: { | ||
chunks: 'initial', | ||
name: 'vendors', | ||
test: /[\\/]node_modules[\\/]/, | ||
enforce: true | ||
} | ||
} | ||
}, | ||
runtimeChunk: true | ||
}, | ||
plugins: [ | ||
new WorkboxPlugin.GenerateSW({ | ||
clientsClaim: true, | ||
skipWaiting: true | ||
}) | ||
] | ||
}); |