Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #841 from LiskHQ/833-webpack-for-electron
Browse files Browse the repository at this point in the history
Add Webpack configuration for the electron app - Closes #833
  • Loading branch information
reyraa authored Oct 9, 2017
2 parents afaa600 + 4bc0740 commit 3d17420
Show file tree
Hide file tree
Showing 15 changed files with 370 additions and 177 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,20 @@ npm run build

### Start

Start the Electron client.

Start the Electron client. Before staring you need to make sure the application is built. If you need to built the entire application, run

```
npm run build
```

as mentioned before. And if you want to solely build electron app, run

```
npm run build-electron
```

Then, in order to launch electron, you can run

```
npm run start
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lisk-nano",
"version": "1.1.0",
"description": "Lisk Nano",
"main": "main.js",
"main": "./dist/main.js",
"author":{
"name": "Lisk Foundation",
"email": "admin@lisk.io"
Expand Down
File renamed without changes.
11 changes: 5 additions & 6 deletions app/main.js → app/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const electron = require('electron'); // eslint-disable-line import/no-extraneous-dependencies
const path = require('path');
const buildMenu = require('./menu');
import electron from 'electron'; // eslint-disable-line import/no-extraneous-dependencies
import path from 'path';
import buildMenu from './menu';

const { app, BrowserWindow, Menu, ipcMain } = electron;

Expand Down Expand Up @@ -29,7 +29,7 @@ function createWindow() {
// Avoid app throttling when Electron is in background
backgroundThrottling: false,
// Specifies a script that will be loaded before other scripts run in the page.
preload: path.resolve(__dirname, 'ipc.js'),
preload: path.resolve(__dirname, '../src/ipc.js'),
},
});
win.on('blur', () => win.webContents.send('blur'));
Expand All @@ -40,8 +40,7 @@ function createWindow() {
}

Menu.setApplicationMenu(buildMenu(app, copyright));

win.loadURL(`file://${__dirname}/dist/index.html`);
win.loadURL(`file://${__dirname}/index.html`);

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

Expand Down
4 changes: 2 additions & 2 deletions app/menu.js → app/src/menu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const electron = require('electron'); // eslint-disable-line import/no-extraneous-dependencies
import electron from 'electron'; // eslint-disable-line import/no-extraneous-dependencies

const { Menu } = electron;

Expand Down Expand Up @@ -94,7 +94,7 @@ const template = [
},
];

module.exports = (app, copyright) => {
export default (app, copyright) => {
if (process.platform === 'darwin') {
const name = app.getName();
template.unshift({
Expand Down
6 changes: 6 additions & 0 deletions config/reactToolbox.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
'color-primary': '#0288D1',
'color-primary-dark': '#0288D1',
'button-border-radius': '3px',
'input-text-label-color': 'rgba(0,0,0,0.38)',
};
76 changes: 76 additions & 0 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const { resolve } = require('path');
const merge = require('webpack-merge');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const baseConfig = require('./webpack.config');
const reactConfig = require('./webpack.config.react');
const reactToolboxVariables = require('./reactToolbox.config');
/* eslint-enable import/no-extraneous-dependencies */

module.exports = merge(baseConfig, reactConfig, {
output: {
path: resolve(__dirname, '../app', '../dist'),
filename: 'bundle.[name].js',
},
devServer: {
contentBase: 'src',
inline: true,
port: 8080,
historyApiFallback: true,
},
plugins: [
new webpack.DefinePlugin({
PRODUCTION: false,
TEST: false,
// because of https://fb.me/react-minification
'process.env': {
NODE_ENV: null,
},
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
}),
],
module: {
rules: [
{
test: /\.css$/,
use: ['css-hot-loader'].concat(ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: true,
importLoaders: 1,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
sourceComments: true,
plugins: [
// eslint-disable-next-line import/no-extraneous-dependencies
require('postcss-partial-import')({}),
require('postcss-cssnext')({
features: {
customProperties: {
variables: reactToolboxVariables,
},
},
}),
// eslint-disable-next-line import/no-extraneous-dependencies
require('postcss-for')({}),
],
},
},
],
})),
},
],
},
});
17 changes: 17 additions & 0 deletions config/webpack.config.electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable import/no-extraneous-dependencies */
const { resolve } = require('path');
const merge = require('webpack-merge');
const baseConfig = require('./webpack.config');
/* eslint-enable import/no-extraneous-dependencies */

module.exports = merge(baseConfig, {
entry: `${resolve(__dirname, '../app/src')}/main.js`,
output: {
path: resolve(__dirname, '../app/dist'),
filename: 'main.js',
},
target: 'electron-renderer',
node: {
__dirname: false,
},
});
39 changes: 39 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
node: {
fs: 'empty',
child_process: 'empty',
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {},
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['es2015', 'react', 'stage-3'],
plugins: ['syntax-trailing-function-commas'],
env: {
test: {
plugins: ['istanbul'],
},
},
},
},
{
test: /\.(eot|svg|ttf|woff|woff2|png)$/,
loader: 'url-loader',
},
{
test: /\.json$/,
loaders: ['json-loader'],
},
],
},
};
76 changes: 76 additions & 0 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const { resolve } = require('path');
const merge = require('webpack-merge');
const { NamedModulesPlugin } = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const baseConfig = require('./webpack.config');
const reactConfig = require('./webpack.config.react');
const reactToolboxVariables = require('./reactToolbox.config');
/* eslint-enable import/no-extraneous-dependencies */

module.exports = merge(baseConfig, reactConfig, {
output: {
path: resolve(__dirname, '../app', '../app/dist'),
filename: 'bundle.[name].js',
},
plugins: [
new webpack.DefinePlugin({
PRODUCTION: true,
TEST: false,
// because of https://fb.me/react-minification
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
mangle: false,
}),
new NamedModulesPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
}),
],
module: {
rules: [
{
test: /\.css$/,
use: ['css-hot-loader'].concat(ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: false,
modules: true,
importLoaders: 1,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: false,
sourceComments: false,
plugins: [
// eslint-disable-next-line import/no-extraneous-dependencies
require('postcss-partial-import')({}),
require('postcss-cssnext')({
features: {
customProperties: {
variables: reactToolboxVariables,
},
},
}),
// eslint-disable-next-line import/no-extraneous-dependencies
require('postcss-for')({}),
],
},
},
],
})),
},
],
},
});
41 changes: 41 additions & 0 deletions config/webpack.config.react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable import/no-extraneous-dependencies */
const { resolve } = require('path');
const webpack = require('webpack');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
/* eslint-enable import/no-extraneous-dependencies */

const entries = {
app: `${resolve(__dirname, '../src')}/main.js`,
vendor: ['react', 'redux', 'react-dom'],
};

module.exports = {
entry: entries,
devtool: 'source-map',
devServer: {
contentBase: 'src',
inline: true,
port: 8080,
historyApiFallback: true,
},
plugins: [
new StyleLintPlugin({
context: `${resolve(__dirname, '../src')}/`,
files: '**/*.css',
config: {
extends: 'stylelint-config-standard',
rules: {
'selector-pseudo-class-no-unknown': null,
'unit-whitelist': ['px', 'deg', '%', 'em', 'ms'],
'length-zero-no-unit': null,
},
ignoreFiles: './node_modules/**/*.css',
},
}),
new ExtractTextPlugin({
filename: 'styles.css',
allChunks: true,
}),
],
};
Loading

0 comments on commit 3d17420

Please sign in to comment.