Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mzwing committed Jul 23, 2022
0 parents commit 7a3a44e
Show file tree
Hide file tree
Showing 17 changed files with 3,954 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
119 changes: 119 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
module.exports = {
env: {
browser: true,
es2022: true,
},
extends: [
"eslint:recommended",
"plugin:jsonc/recommended-with-jsonc",
"plugin:yml/standard",
"plugin:markdown/recommended",
],
ignorePatterns: [
"*.min.*",
"CHANGELOG.md",
"dist",
"LICENSE*",
"output",
"coverage",
"public",
"temp",
"packages-lock.json",
"pnpm-lock.yaml",
"yarn.lock",
"__snapshots__",
"!.github",
"!.vitepress",
"!.vscode",
],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module"
},
overrides: [
{
files: ["*.json", "*.json5"],
parser: "jsonc-eslint-parser",
rules: {
quotes: ["warn", "double"],
"quote-props": ["warn", "consistent-as-needed"],
"comma-dangle": ["warn", "always"],
},
},
{
files: ["package.json"],
parser: "jsonc-eslint-parser",
rules: {
"jsonc/sort-keys": [
"warn",
{
pathPattern: "^$",
order: [
"name",
"type",
"version",
"private",
"packageManager",
"description",
"keywords",
"license",
"author",
"repository",
"funding",
"main",
"module",
"types",
"unpkg",
"jsdelivr",
"exports",
"files",
"bin",
"sideEffects",
"scripts",
"peerDependencies",
"peerDependenciesMeta",
"dependencies",
"optionalDependencies",
"devDependencies",
"husky",
"lint-staged",
"eslintConfig",
],
},
{
pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies$",
order: { type: "asc" },
},
],
},
},
{
files: ["*.*js"],
rules: {
"no-unused-vars": "off",
"no-undef": "off",
"no-eval": "warn",
"no-empty": "warn",
"no-extra-semi": "warn",
},
},
{
// Code blocks in markdown file
files: ["**/*.md/*.*"],
rules: {
"import/no-unresolved": "off",
"no-alert": "off",
"no-console": "off",
"no-restricted-imports": "off",
"no-undef": "off",
"no-unused-expressions": "off",
"no-unused-vars": "off",
},
},
],
rules: {
indent: ["error", 2],
quotes: ["error", "double"],
semi: ["error", "always"],
},
};
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 mt-vite

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
65 changes: 65 additions & 0 deletions electron-builder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"appId": "com.github.mt-vite.mt-vite-react-demo-electron",
"productName": "MTViteReactDemoElectron",
"asar": true,
"win": {
"target": {
"target": "nsis",
"arch": [
"x64"
]
}
},
"nsis": {
"oneClick": false,
"allowToChangeInstallationDirectory": true
},
"linux": {
"executableName": "mt-vite-react-demo-electron",
"description": "mt-vite react demo",
"desktop": {
"StartupWMClass": "mt-vite-react-demo-electron",
"Keywords": "vite;electron;react-js"
},
"target": [
"deb",
"tar.gz",
"Appimage"
]
},
"dmg": {
"contents": [
{
"x": 410,
"y": 230,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 230,
"type": "file"
}
]
},
"mac": {
"target": [
{
"target": "dmg",
"arch": [
"x64",
"arm64"
]
}
],
"type": "distribution"
},
"files": [
"dist/**/*",
"electron/**/*"
],
"directories": {
"buildResources": "assets",
"output": "dist_electron"
}
}
47 changes: 47 additions & 0 deletions electron/main.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow } = require("electron");
const path = require("path");

const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, "./preload/preload.cjs")
}
});

// Load content.
mainWindow.loadURL(
process.env.NODE_ENV === "development"
? "http://localhost:5173"
:`file://${path.join(__dirname, "../dist/index.html")}`
);

// Open the DevTools.
// mainWindow.webContents.openDevTools();
};

// 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.whenReady().then(() => {
createWindow();

app.on("activate", () => {
// On macOS 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 (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});

// 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.
12 changes: 12 additions & 0 deletions electron/preload/preload.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
window.addEventListener("DOMContentLoaded", () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector);
if (element) element.innerText = text;
};

for (const dependency of ["chrome", "node", "electron"]) {
replaceText(`${dependency}-version`, process.versions[dependency]);
}
});
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
56 changes: 56 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "mt-vite-react-demo",
"version": "0.0.1",
"description": "mt-vite react demo",
"license": "MIT",
"author": {
"name": "mzwing",
"email": "[email protected]"
},
"repository": {
"type": "git",
"url": "[email protected]:mt-vite/mt-vite-react-demo.git"
},
"main": "./electron/main.cjs",
"scripts": {
"dev:web": "vite --port 5173",
"dev:electron": "concurrently -k \"vite --port 5173\" \"wait-on tcp:5173 && cross-env NODE_ENV=development electron .\"",
"preview:web": "vite preview",
"preview:electron": "vite build && electron .",
"build:web": "vite build",
"build:win": "vite build && electron-builder build --win --publish=never",
"build:linux": "vite build && electron-builder build --linux --publish=never",
"build:mac": "vite build && electron-builder build --mac --publish=never",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:html": "htmlhint \"**/*.html\""
},
"maintainers": [
"mzwing",
"so1ve",
"chihuo2104"
],
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.0.0",
"concurrently": "^7.3.0",
"cross-env": "^7.0.3",
"electron": "^19.0.9",
"electron-builder": "^23.1.0",
"eslint": "^8.20.0",
"eslint-plugin-jsonc": "^2.3.1",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-yml": "^1.0.0",
"htmlhint": "^1.1.4",
"vite": "^3.0.0",
"wait-on": "^6.0.1"
},
"bugs": {
"url": "https://github.com/mt-vite/mt-vite-react-demo/issues"
}
}
Loading

0 comments on commit 7a3a44e

Please sign in to comment.