Skip to content

Commit

Permalink
electron minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
ponsfrilus committed Mar 4, 2017
1 parent ebf64f9 commit ab1f8de
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 0 deletions.
3 changes: 3 additions & 0 deletions electron/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/*.js
config/*.js
dist/*.js
17 changes: 17 additions & 0 deletions electron/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
root: true,
parserOptions: {
sourceType: 'module'
},
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard',
// add your custom rules here
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
'one-var': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
'brace-style': [2, 'stroustrup', { 'allowSingleLine': true }]
}
}
5 changes: 5 additions & 0 deletions electron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
node_modules/
dist/
npm-debug.log
npm-debug.log.*
40 changes: 40 additions & 0 deletions electron/build/script.build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
process.env.NODE_ENV = 'production'

if (process.argv.length > 2) {
process.env.PLATFORM_TARGET = process.argv[2]
}

require('colors')

var
packager = require('electron-packager'),
shell = require('shelljs'),
path = require('path'),
fs = require('fs'),
config = require('../config/electron'),
targetPath = path.join(__dirname, '../../dist'),
webpackBuild = require('./webpack.builder.js')

if (!fs.existsSync(targetPath)) {
console.error('Please build your App before packaging for Electron...'.red)
console.error('Issue "quasar build"'.red + ' from the root folder of your project'.gray + ' to make the build then try again.'.red)
process.exit(1)
}

webpackBuild(function () {
shell.cp(path.join(__dirname, '../dist/electron.js'), targetPath)
shell.cp(path.join(__dirname, '../package.json'), targetPath)

console.log(' Building Quasar Electron app(s)...\n'.bold)
packager(config, (err, appPaths) => {
if (err) {
console.error('Error from `electron-packager` when building app...'.red)
console.error(err)
return
}

console.log(' Build(s) were successful.')
console.log(appPaths)
console.log('\n Done!'.bold + ' Check ' + path.resolve(__dirname, '../dist').gray + ' folder.')
})
})
6 changes: 6 additions & 0 deletions electron/build/script.clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var
shell = require('shelljs'),
path = require('path')

shell.rm('-rf', path.resolve(__dirname, '../dist'))
console.log(' Cleaned Electron build artifacts.\n')
28 changes: 28 additions & 0 deletions electron/build/webpack.builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var
webpackConfig = require('./webpack.conf'),
webpack = require('webpack')

module.exports = function (done) {
console.log((' Building Electron entry main.js...\n').bold)

webpack(webpackConfig, function (err, stats) {
if (err || (stats.compilation.errors && stats.compilation.errors.length)) {
console.log(stats.compilation.errors.toString({
colors: true
}))
return
}

console.log(stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n')

console.log('\n Build complete for Electron main.js into dist/electron.js\n')

done && done()
})
}
90 changes: 90 additions & 0 deletions electron/build/webpack.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
var
path = require('path'),
webpack = require('webpack'),
config = require('../config/webpack'),
merge = require('webpack-merge'),
ProgressBarPlugin = require('progress-bar-webpack-plugin')

function resolve (dir) {
return path.join(__dirname, '..', dir)
}

var folders = {
src: resolve('src'),
node_modules: resolve('node_modules'),
dist: resolve('dist')
}

module.exports = {
entry: {
app: './src/main.js'
},
target: 'node',
externals: config.externals,
output: {
filename: 'electron.js',
libraryTarget: 'commonjs2',
path: folders.dist
},
resolve: {
extensions: ['.js', '.json', '.node'],
modules: [
folders.src,
folders.node_modules
]
},
node: {
__dirname: false,
__filename: false
},
module: {
rules: [
{ // eslint
enforce: 'pre',
test: /\.js$/,
loader: 'eslint-loader',
include: folders.src,
exclude: /node_modules/,
options: {
formatter: require('eslint-friendly-formatter')
}
},
{
test: /\.js$/,
loader: 'babel-loader',
include: folders.src,
exclude: /node_modules/
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.node$/,
loader: 'node-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': config.env
}),
new webpack.LoaderOptionsPlugin({
minimize: true
}),
// Progress Bar Webpack plugin format
// https://github.com/clessg/progress-bar-webpack-plugin#options
new ProgressBarPlugin({
format: ' [:bar] ' + ':percent'.bold + ' (:msg)'
}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false
}
})
],
performance: {
hints: false
}
}
3 changes: 3 additions & 0 deletions electron/config/build.env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
NODE_ENV: '"production"'
}
18 changes: 18 additions & 0 deletions electron/config/electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require('path')

module.exports = {
// electron-packager options
// Docs: https://simulatedgreg.gitbooks.io/electron-vue/content/docs/building_your_app.html
name: 'EPFLDojoApp',

// Electron version
electronVersion: require('../node_modules/electron/package.json').version,
arch: 'x64',
asar: true,
dir: path.join(__dirname, '../../dist'),
icon: path.join(__dirname, '../icons/icon'),
ignore: /\b(node_modules|src|icons)\b/,
out: path.join(__dirname, '../dist'),
overwrite: true,
platform: process.env.PLATFORM_TARGET || 'all'
}
8 changes: 8 additions & 0 deletions electron/config/webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
externals: {
electron: 'electron',
path: 'path'
},

env: require('./build.env')
}
Binary file added electron/icons/icon.icns
Binary file not shown.
Binary file added electron/icons/icon.ico
Binary file not shown.
30 changes: 30 additions & 0 deletions electron/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "EPFLDojoApp",
"version": "0.0.1",
"author": "EPFL-Dojo",
"description": "EPFL Dojo app",
"main": "electron.js",
"scripts": {
"dev": "cross-env NODE_ENV=development electron src/main.js",
"clean": "node build/script.clean.js",
"build": "node build/script.build.js"
},
"devDependencies": {
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"colors": "^1.1.2",
"cross-env": "~3.1.4",
"devtron": "^1.4.0",
"electron": "^1.5.0",
"electron-devtools-installer": "^2.0.1",
"electron-packager": "^8.2.0",
"eslint": "^3.16.0",
"eslint-friendly-formatter": "^2.0.7",
"eslint-loader": "^1.6.2",
"json-loader": "^0.5.4",
"node-loader": "^0.6.0",
"shelljs": "^0.7.5",
"webpack": "^2.2.1",
"webpack-merge": "^3.0.0"
}
}
53 changes: 53 additions & 0 deletions electron/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict'

const
electron = require('electron'),
path = require('path'),
app = electron.app,
BrowserWindow = electron.BrowserWindow

let mainWindow

function createWindow () {
/**
* Initial window options
*/
mainWindow = new BrowserWindow({
height: 600,
width: 800
})

mainWindow.loadURL(
process.env.NODE_ENV === 'production'
? `file://${__dirname}/index.html`
: `http://localhost:${process.env.PORT || require('../../config').dev.port}`
)

if (process.env.NODE_ENV === 'development') {
BrowserWindow.addDevToolsExtension(path.join(__dirname, '../node_modules/devtron'))

let installExtension = require('electron-devtools-installer')

installExtension.default(installExtension.VUEJS_DEVTOOLS)
.then(name => mainWindow.webContents.openDevTools())
.catch(err => console.log('An error occurred: ', err))
}

mainWindow.on('closed', () => {
mainWindow = null
})
}

app.on('ready', createWindow)

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})

0 comments on commit ab1f8de

Please sign in to comment.