Skip to content

Commit

Permalink
chore: electron integrate with react (for basic setting)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcomplete committed Mar 28, 2023
1 parent 19db040 commit 0f24c63
Show file tree
Hide file tree
Showing 16 changed files with 6,955 additions and 101 deletions.
31 changes: 23 additions & 8 deletions app/electron/package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
{
"private": true,
"main": "main/index.js",
"main": "dist/index.js",
"productName": "huntly",
"scripts": {
"clean": "rimraf dist main",
"dev": "npm run build-electron && electron .",
"build-electron": "tsc -p src",
"clean": "rimraf dist",
"start:renderer": "webpack --config webpack/webpack.dev.js --watch",
"dev": "webpack --config webpack/webpack.dev.js && npm run build-electron && electron .",
"build-electron": "tsc -p src/main",
"build": "npm run build-electron",
"pack-app": "npm run build && electron-builder --dir",
"dist": "npm run build && electron-builder",
"type-check": "tsc -p src/tsconfig.json",
"type-check": "tsc -p src/main/tsconfig.json",
"lint": "eslint ."
},
"dependencies": {
"app-root-path": "^3.1.0",
"electron-is-dev": "^1.2.0",
"electron-window-state": "^5.0.3"
"electron-window-state": "^5.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@electron-forge/cli": "^6.0.5",
"@electron-forge/plugin-webpack": "^6.0.5",
"@types/node": "^17.0.40",
"@types/react": "^18.0.30",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.3",
"electron": "^19.0.3",
"electron-builder": "^23.0.3",
"electron-forge": "^5.2.4",
"eslint": "^8.17.0",
"rimraf": "^3.0.0",
"typescript": "^4.7.3"
"style-loader": "^3.3.2",
"ts-loader": "^9.4.2",
"typescript": "^4.7.3",
"webpack": "^5.76.3",
"webpack-cli": "^5.0.1",
"webpack-merge": "^5.8.0"
},
"build": {
"asar": true,
"files": [
"main"
"dist"
]
}
}
13 changes: 13 additions & 0 deletions app/electron/public/renderer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Huntly Extension Options</title>
<script src="vendor.js"></script>
</head>

<body>
<div id="root"></div>
<script src="app.js"></script>
</body>
</html>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ app.on("ready", async () => {
const url = isDev
? 'http://localhost:3000/'
: format({
pathname: join(__dirname, '../renderer/out/index.html'),
pathname: join(__dirname, './renderer/index.html'),
protocol: 'file:',
slashes: true,
})
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"skipLibCheck": true,
"strict": true,
"target": "esnext",
"outDir": "../main"
"outDir": "../../dist/"
},
"exclude": ["node_modules"],
"include": ["**/*.ts", "**/*.tsx", "**/*.js"]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions app/electron/src/renderer/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {createRoot} from "react-dom/client";

export default function App() {
//todo add basic setting modal
return <div>hello</div>
}

const root = createRoot(
document.getElementById("root") as HTMLElement
);

root.render(
<App/>
);
Empty file.
18 changes: 18 additions & 0 deletions app/electron/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"incremental": true,
"target": "es2021",
"module": "commonjs",
"lib": ["dom", "es2021"],
"jsx": "react-jsx",
"strict": true,
"sourceMap": true,
"baseUrl": "./src",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"allowJs": true,
},
"exclude": ["test", "release/build", "release/app/dist"]
}
44 changes: 44 additions & 0 deletions app/electron/webpack/webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const webpack = require("webpack");
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const srcDir = path.join(__dirname, "..", "src/renderer");

module.exports = {
entry: {
app: path.join(srcDir, 'App.tsx'),
},
output: {
path: path.join(__dirname, "../dist/renderer/"),
filename: "[name].js",
},
optimization: {
splitChunks: {
name: "vendor",
},
},
module: {
rules: [
{
test: /\.css$/i,
use: [
{loader: "style-loader"},
{loader: "css-loader"}
]
},
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".css"],
},
plugins: [
new CopyPlugin({
patterns: [{from: ".", to: "../", context: "public"}],
options: {},
}),
],
};
7 changes: 7 additions & 0 deletions app/electron/webpack/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');

module.exports = merge(common, {
devtool: 'inline-source-map',
mode: 'development',
});
6 changes: 6 additions & 0 deletions app/electron/webpack/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');

module.exports = merge(common, {
mode: 'production'
});
Loading

0 comments on commit 0f24c63

Please sign in to comment.