├── .gitignore ├── .babelrc ├── src ├── renderer │ ├── index.css │ ├── index.js │ ├── index.html │ └── App │ │ ├── App.css │ │ ├── images │ │ ├── javascript-icon.svg │ │ ├── electron-icon.svg │ │ └── react-icon.svg │ │ └── App.jsx └── main │ └── index.js ├── .travis.yml ├── LICENSE ├── webpack.config.js ├── package.json ├── README.md └── CODE_OF_CONDUCT.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env", "@babel/preset-react"] 3 | } 4 | -------------------------------------------------------------------------------- /src/renderer/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | box-sizing: border-box; 5 | font-size: 10px; 6 | } 7 | -------------------------------------------------------------------------------- /src/renderer/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App/App'; 4 | import './index.css'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "stable" 4 | cache: 5 | directories: 6 | - node_modules 7 | jobs: 8 | include: 9 | - stage: Test 10 | script: 11 | - npm run webpack-dev 12 | - npm run webpack-prod -------------------------------------------------------------------------------- /src/renderer/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Electron React JavaScript Boilerplate 7 | 8 | 9 | 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Armin Dizdarevic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/index.js: -------------------------------------------------------------------------------- 1 | import { app, BrowserWindow } from 'electron'; 2 | 3 | let mainWindow = null; 4 | const isDev = process.env.ELECTRON_ENV == 'dev'; 5 | 6 | //Render main window w/ configuration settings 7 | const renderWindow = async () => { 8 | mainWindow = new BrowserWindow({ 9 | width: 1200, 10 | height: 800, 11 | minWidth: 640, 12 | minHeight: 480, 13 | center: true, 14 | webPreferences: { 15 | nodeIntegration: true, 16 | devTools: isDev 17 | } 18 | }); 19 | 20 | // Depending on the environment the frontend will either load from the react server or the static html file 21 | if (isDev) { 22 | mainWindow.loadURL('http://localhost:3000/'); 23 | } else { 24 | mainWindow.loadFile('./build/index.html'); 25 | } 26 | 27 | // Detect if devtools was somehow opened outside development 28 | mainWindow.webContents.on('devtools-opened', () => { 29 | if (!isDev) { 30 | mainWindow.webContents.closeDevTools(); 31 | } 32 | }); 33 | }; 34 | 35 | app.on('ready', renderWindow); 36 | 37 | app.on('window-all-closed', () => { 38 | if (process.platform !== 'darwin') { 39 | app.quit(); 40 | } 41 | }); 42 | 43 | app.on('activate', () => { 44 | if (mainWindow === null) { 45 | renderWindow(); 46 | } 47 | }); 48 | -------------------------------------------------------------------------------- /src/renderer/App/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | background-color: #282c34; 3 | text-align: center; 4 | min-height: 100vh; 5 | display: flex; 6 | flex-direction: row; 7 | align-items: center; 8 | justify-content: space-evenly; 9 | } 10 | 11 | .App-logo { 12 | height: 30vmin; 13 | pointer-events: none; 14 | margin-bottom: 2em; 15 | } 16 | 17 | .App-link { 18 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 19 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 20 | sans-serif; 21 | -webkit-font-smoothing: antialiased; 22 | -moz-osx-font-smoothing: grayscale; 23 | text-decoration: none; 24 | font-size: calc(1em + 2vmin); 25 | font-weight: bold; 26 | } 27 | 28 | #react-link { 29 | color: #61dafb; 30 | } 31 | 32 | #electron-link { 33 | color: #47848f; 34 | } 35 | 36 | #javascript-link { 37 | color: #f7df1e; 38 | } 39 | 40 | .container { 41 | display: flex; 42 | flex-direction: column; 43 | } 44 | 45 | @media (prefers-reduced-motion: no-preference) { 46 | #react-logo, 47 | #electron-logo { 48 | animation: App-logo-spin infinite 20s linear; 49 | } 50 | } 51 | 52 | @keyframes App-logo-spin { 53 | from { 54 | transform: rotate(0deg); 55 | } 56 | to { 57 | transform: rotate(360deg); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const HtmlWebPackPlugin = require('html-webpack-plugin'); 3 | 4 | module.exports = [ 5 | { 6 | entry: './src/main/index.js', 7 | name: 'electron', 8 | target: 'electron-main', 9 | resolve: { 10 | extensions: ['*', '.js', '.json'] 11 | }, 12 | output: { 13 | path: __dirname + '/build', 14 | publicPath: '/', 15 | filename: 'app.js' 16 | }, 17 | plugins: [] 18 | }, 19 | { 20 | entry: './src/renderer/index.js', 21 | name: 'react', 22 | target: 'electron-renderer', 23 | module: { 24 | rules: [ 25 | { 26 | test: /\.(js|jsx)$/, 27 | exclude: /node_modules/, 28 | use: ['babel-loader'] 29 | }, 30 | { test: /\.css$/, use: ['style-loader', 'css-loader'] }, 31 | { 32 | test: /\.(png|svg|jpg|gif)$/, 33 | use: ['file-loader'] 34 | } 35 | ] 36 | }, 37 | resolve: { 38 | extensions: ['*', '.js', '.jsx', '.json', '.css', '.svg'] 39 | }, 40 | output: { 41 | path: __dirname + '/build', 42 | publicPath: './', 43 | filename: 'bundle.js' 44 | }, 45 | devServer: { 46 | contentBase: __dirname + '/build/', 47 | compress: true 48 | }, 49 | plugins: [ 50 | new HtmlWebPackPlugin({ 51 | filename: 'index.html', 52 | template: 'src/renderer/index.html' 53 | }) 54 | ] 55 | } 56 | ]; 57 | -------------------------------------------------------------------------------- /src/renderer/App/images/javascript-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-react-javascript-boilerplate", 3 | "version": "0.0.1", 4 | "description": "A minimal template for creating electron applications using the react framework with JavaScript.", 5 | "main": "./src/main/index.js", 6 | "scripts": { 7 | "webpack-dev": "webpack --mode development", 8 | "react-dev": "webpack-dev-server --mode development --port 3000", 9 | "electron-dev": "cross-env ELECTRON_ENV=dev electron ./build/app.js", 10 | "webpack-prod": "webpack --mode production", 11 | "build-win": "electron-builder build --win -c.extraMetadata.main=./build/app.js --publish never" 12 | }, 13 | "author": "Armin Dizdarevic", 14 | "license": "MIT", 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/arevi/electron-react-javascript-boilerplate" 18 | }, 19 | "build": { 20 | "appId": "com.arevi.electron-react-javascript-boilerplate", 21 | "files": [ 22 | "build/*", 23 | "node_modules/**/*" 24 | ], 25 | "productName": "Electron React JavaScript Boilerplate" 26 | }, 27 | "dependencies": { 28 | "react": "^16.13.1", 29 | "react-dom": "^16.13.1" 30 | }, 31 | "devDependencies": { 32 | "@babel/core": "^7.11.6", 33 | "@babel/preset-env": "^7.11.5", 34 | "@babel/preset-react": "^7.10.4", 35 | "babel-loader": "^8.1.0", 36 | "cross-env": "^7.0.2", 37 | "css-loader": "^4.3.0", 38 | "electron": "^10.1.2", 39 | "electron-builder": "^22.8.1", 40 | "file-loader": "^6.1.0", 41 | "html-webpack-plugin": "^4.4.1", 42 | "style-loader": "^1.2.1", 43 | "webpack": "^4.44.1", 44 | "webpack-cli": "^3.3.12", 45 | "webpack-dev-server": "^3.11.0" 46 | } 47 | } -------------------------------------------------------------------------------- /src/renderer/App/App.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import reactLogo from './images/react-icon.svg'; 3 | import electronLogo from './images/electron-icon.svg'; 4 | import jsLogo from './images/javascript-icon.svg'; 5 | import './App.css'; 6 | 7 | function App() { 8 | return ( 9 |
10 |
11 | 17 | 24 | Learn React 25 | 26 |
27 |
28 | 34 | 41 | Learn JavaScript 42 | 43 |
44 |
45 | 51 | 58 | Learn Electron 59 | 60 |
61 |
62 | ); 63 | } 64 | 65 | export default App; 66 | -------------------------------------------------------------------------------- /src/renderer/App/images/electron-icon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/renderer/App/images/react-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Electron-React-JavaScript-Boilerplate - Documentation 2 | 3 | ![Screenshot](https://i.imgur.com/FLSVIPW.png 'Screenshot') 4 | 5 | This template serves as the basis for creating extensible electron applications using the React frontend framework, all transpiled by webpack allowing for the latest ECMAScript standards to be used. 6 | 7 | This template is minimal, by design, reducing the overhead required for customization. Out of the box, it will feature minimal pages that need to be modified. This results in less time being spent cleaning up unused portions of the code, and less time to production. 8 | 9 |

10 | 11 | 12 | 13 |

14 | 15 | ## Getting Started 16 | 17 | | Command | Effect | 18 | | ------------- | ------------------------------------------------------------------------ | 19 | | `npm install` | Install all of the required node modules and dependencies for the project | 20 | 21 | ## Development Commands 22 | 23 | The following commands with allow for an intuitive development environment with the application hot reloading on any frontend application changes. 24 | **The application will not hot reload on electron changes.** 25 | 26 | | Command | Effect | 27 | | -------------- | ------------------------------------------------------------------------ | 28 | | `webpack-dev` | Compiles a development version of all applicable files (main & renderer) | 29 | | `react-dev` | Launches a live webpack development server on port 3000 | 30 | | `electron-dev` | Launches electron and connects to port 3000 | 31 | 32 | > The `react-dev` command must be ran prior to `electron-dev` to connect to the local server. 33 | 34 | > While in `Development` mode Chrome Developer Tools can be opened via Ctrl+Shift+I. 35 | 36 | ## Production Commands 37 | 38 | The following commands with compile the application for win32 platform machines. 39 | 40 | | Command | Effect | 41 | | -------------- | ----------------------------------------------------------------------- | 42 | | `webpack-prod` | Compiles a production version of all applicable files (main & renderer) | 43 | | `build-win` | Compiles the production files to a Windows executable | 44 | 45 | > While in `Production` mode Chrome Developer Tools is disabled. 46 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at arevi.dev@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | --------------------------------------------------------------------------------