Compare commits
7 Commits
main
...
electron-m
| Author | SHA1 | Date |
|---|---|---|
|
|
006d93229c | |
|
|
563f2b470e | |
|
|
99cabf048d | |
|
|
941f0cc96c | |
|
|
8dfa1778e8 | |
|
|
9a2577465e | |
|
|
d4c4215b08 |
|
|
@ -2,7 +2,7 @@
|
|||
VITE_USE_MOCK = true
|
||||
|
||||
# public path
|
||||
VITE_PUBLIC_PATH = /
|
||||
VITE_PUBLIC_PATH = ./
|
||||
|
||||
# Delete console
|
||||
VITE_DROP_CONSOLE = true
|
||||
|
|
|
|||
|
|
@ -1,118 +0,0 @@
|
|||
name: deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
# push-to-ftp:
|
||||
# if: "contains(github.event.head_commit.message, '[deploy]')"
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - name: Checkout
|
||||
# uses: actions/checkout@v2
|
||||
|
||||
# - name: Sed Config Base
|
||||
# shell: bash
|
||||
# run: |
|
||||
# sed -i 's#VITE_PUBLIC_PATH\s*=.*#VITE_PUBLIC_PATH = /next/#g' ./.env.production
|
||||
# sed -i "s#VITE_BUILD_COMPRESS\s*=.*#VITE_BUILD_COMPRESS = 'gzip'#g" ./.env.production
|
||||
# cat ./.env.production
|
||||
|
||||
# - name: use Node.js 14
|
||||
# uses: actions/setup-node@v2.1.2
|
||||
# with:
|
||||
# node-version: '14.x'
|
||||
|
||||
# - name: Get yarn cache
|
||||
# id: yarn-cache
|
||||
# run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
|
||||
# - name: Cache dependencies
|
||||
# uses: actions/cache@v2
|
||||
# with:
|
||||
# path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
# key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
# restore-keys: |
|
||||
# ${{ runner.os }}-yarn-
|
||||
|
||||
# - name: Build
|
||||
# run: |
|
||||
# yarn install
|
||||
# yarn run build
|
||||
|
||||
# - name: Deploy
|
||||
# uses: SamKirkland/FTP-Deploy-Action@2.0.0
|
||||
# env:
|
||||
# FTP_SERVER: ${{ secrets.FTP_SERVER }}
|
||||
# FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
|
||||
# FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
|
||||
# METHOD: sftp
|
||||
# PORT: ${{ secrets.FTP_PORT }}
|
||||
# LOCAL_DIR: dist
|
||||
# REMOTE_DIR: /srv/www/vben-admin
|
||||
# ARGS: --delete --verbose --parallel=80
|
||||
|
||||
push-to-gh-pages:
|
||||
if: "contains(github.event.head_commit.message, '[release]')"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Sed Config Base
|
||||
shell: bash
|
||||
run: |
|
||||
sed -i 's#VITE_PUBLIC_PATH\s*=.*#VITE_PUBLIC_PATH = /vue-vben-admin/#g' ./.env.production
|
||||
sed -i "s#VITE_BUILD_COMPRESS\s*=.*#VITE_BUILD_COMPRESS = 'gzip'#g" ./.env.production
|
||||
cat ./.env.production
|
||||
|
||||
- name: use Node.js 16
|
||||
uses: actions/setup-node@v2.1.2
|
||||
with:
|
||||
node-version: '16.x'
|
||||
|
||||
- name: Get yarn cache
|
||||
id: yarn-cache
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
|
||||
- name: Set SSH Environment
|
||||
env:
|
||||
DOCS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||
run: |
|
||||
mkdir -p ~/.ssh/
|
||||
echo "$ACTIONS_DEPLOY_KEY" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan github.com > ~/.ssh/known_hosts
|
||||
chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
|
||||
git config --local user.email "vbenadmin@163.com"
|
||||
git config --local user.name "vbenAdmin"
|
||||
|
||||
- name: Delete gh-pages branch
|
||||
run: |
|
||||
git push origin --delete gh-pages
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
yarn install
|
||||
yarn run build
|
||||
touch dist/.nojekyll
|
||||
cp dist/index.html dist/404.html
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v2.5.0
|
||||
env:
|
||||
ACTIONS_DEPLOY_KEY: ${{secrets.ACTIONS_DEPLOY_KEY}}
|
||||
PUBLISH_BRANCH: gh-pages
|
||||
PUBLISH_DIR: ./dist
|
||||
with:
|
||||
forceOrphan: true
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
name: schedule-push-to-ftp
|
||||
|
||||
# Timed deployment project
|
||||
on:
|
||||
push:
|
||||
schedule:
|
||||
- cron: '0 20 * * *'
|
||||
|
||||
jobs:
|
||||
schedule-push-to-ftp:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Sed Config Base
|
||||
shell: bash
|
||||
run: |
|
||||
sed -i 's#VITE_PUBLIC_PATH\s*=.*#VITE_PUBLIC_PATH = /next/#g' ./.env.production
|
||||
sed -i "s#VITE_BUILD_COMPRESS\s*=.*#VITE_BUILD_COMPRESS = 'gzip'#g" ./.env.production
|
||||
sed -i "s#VITE_DROP_CONSOLE\s*=.*#VITE_DROP_CONSOLE = true#g" ./.env.production
|
||||
cat ./.env.production
|
||||
|
||||
- name: use Node.js 16
|
||||
uses: actions/setup-node@v2.1.2
|
||||
with:
|
||||
node-version: '16.x'
|
||||
|
||||
- name: Get yarn cache
|
||||
id: yarn-cache
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
yarn install
|
||||
yarn run build
|
||||
|
||||
- name: Deploy
|
||||
uses: SamKirkland/FTP-Deploy-Action@2.0.0
|
||||
env:
|
||||
FTP_SERVER: ${{ secrets.FTP_SERVER }}
|
||||
FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
|
||||
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
|
||||
METHOD: sftp
|
||||
PORT: ${{ secrets.FTP_PORT }}
|
||||
LOCAL_DIR: dist
|
||||
REMOTE_DIR: /srv/www/vben-admin
|
||||
ARGS: --delete --verbose --parallel=80
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
import path from 'path';
|
||||
import { RollupOptions } from 'rollup';
|
||||
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import esbuild from 'rollup-plugin-esbuild';
|
||||
import alias from '@rollup/plugin-alias';
|
||||
import json from '@rollup/plugin-json';
|
||||
|
||||
export function getRollupOptions(): RollupOptions {
|
||||
return {
|
||||
input: path.join(__dirname, '../../electron-main/index.ts'),
|
||||
output: {
|
||||
file: path.join(__dirname, '../../dist/main/build.js'),
|
||||
format: 'cjs',
|
||||
name: 'ElectronMainBundle',
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [
|
||||
nodeResolve({ preferBuiltins: true, browser: true }), // 消除碰到 node.js 模块时⚠警告
|
||||
commonjs(),
|
||||
json(),
|
||||
esbuild({
|
||||
// All options are optional
|
||||
include: /\.[jt]sx?$/, // default, inferred from `loaders` option
|
||||
exclude: /node_modules/, // default
|
||||
// watch: process.argv.includes('--watch'), // rollup 中有配置
|
||||
sourceMap: false, // default
|
||||
minify: process.env.NODE_ENV === 'production',
|
||||
target: 'es2017', // default, or 'es20XX', 'esnext'
|
||||
jsxFactory: 'React.createElement',
|
||||
jsxFragment: 'React.Fragment',
|
||||
// Like @rollup/plugin-replace
|
||||
define: {
|
||||
__VERSION__: '"x.y.z"',
|
||||
},
|
||||
// Add extra loaders
|
||||
loaders: {
|
||||
// Add .json files support
|
||||
// require @rollup/plugin-commonjs
|
||||
'.json': 'json',
|
||||
// Enable JSX in .js files too
|
||||
'.js': 'jsx',
|
||||
},
|
||||
}),
|
||||
alias({
|
||||
entries: [{ find: '/@main/', replacement: path.join(__dirname, '../../electron-main') }],
|
||||
}),
|
||||
],
|
||||
external: [
|
||||
'crypto',
|
||||
'assert',
|
||||
'fs',
|
||||
'util',
|
||||
'os',
|
||||
'events',
|
||||
'child_process',
|
||||
'http',
|
||||
'https',
|
||||
'path',
|
||||
'electron',
|
||||
],
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
import rollup, { OutputOptions } from 'rollup';
|
||||
import chalk from 'chalk';
|
||||
import ora from 'ora';
|
||||
import waitOn from 'wait-on';
|
||||
import net from 'net';
|
||||
import { URL } from 'url';
|
||||
import minimist from 'minimist';
|
||||
import electronConnect from 'electron-connect';
|
||||
|
||||
import { getRollupOptions } from '../config/rollupElectronConfig';
|
||||
|
||||
const argv = minimist(process.argv.slice(2));
|
||||
const TAG = '[compiler-electron]';
|
||||
|
||||
export function startCompilerElectron(port = 80) {
|
||||
// 因为 vite 不会重定向到 index.html,所以直接写 index.html 路由。
|
||||
const ELECTRON_URL = `http://localhost:${port}/index.html`;
|
||||
|
||||
const spinner = ora(`${TAG} Electron build...`);
|
||||
const electron = electronConnect.server.create({ stopOnClose: true });
|
||||
const rollupOptions = getRollupOptions();
|
||||
|
||||
function watchFunc() {
|
||||
// once here, all resources are available
|
||||
const watcher = rollup.watch(rollupOptions);
|
||||
watcher.on('change', (filename) => {
|
||||
const log = chalk.green(`change -- ${filename}`);
|
||||
console.log(TAG, log);
|
||||
});
|
||||
watcher.on('event', (ev) => {
|
||||
if (ev.code === 'END') {
|
||||
// init-未启动、started-第一次启动、restarted-重新启动
|
||||
electron.electronState === 'init' ? electron.start() : electron.restart();
|
||||
} else if (ev.code === 'ERROR') {
|
||||
console.log(ev.error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (argv.watch) {
|
||||
waitOn(
|
||||
{
|
||||
resources: [ELECTRON_URL],
|
||||
timeout: 5000,
|
||||
},
|
||||
(err) => {
|
||||
if (err) {
|
||||
const { hostname } = new URL(ELECTRON_URL);
|
||||
const serverSocket = net.connect(port, hostname, () => {
|
||||
watchFunc();
|
||||
});
|
||||
serverSocket.on('error', (e) => {
|
||||
console.log(err);
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
});
|
||||
} else {
|
||||
watchFunc();
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
spinner.start();
|
||||
rollup
|
||||
.rollup(rollupOptions)
|
||||
.then((build) => {
|
||||
spinner.stop();
|
||||
console.log(TAG, chalk.green('Electron build successed.'));
|
||||
build.write(rollupOptions.output as OutputOptions);
|
||||
})
|
||||
.catch((error) => {
|
||||
spinner.stop();
|
||||
console.log(`\n${TAG} ${chalk.red('构建报错')}\n`, error, '\n');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import { createServer } from 'vite';
|
||||
import path from 'path';
|
||||
import { startCompilerElectron } from './compilerElectron';
|
||||
import minimist from 'minimist';
|
||||
|
||||
(async () => {
|
||||
const argv = minimist(process.argv.slice(2));
|
||||
console.log(argv);
|
||||
const isDev = argv.env === 'development';
|
||||
let port: number | undefined = undefined;
|
||||
if (isDev) {
|
||||
const server = await createServer({
|
||||
root: path.resolve(__dirname, '../../'),
|
||||
});
|
||||
|
||||
const app = await server.listen();
|
||||
port = app.config.server.port;
|
||||
process.env.PORT = `${port}`;
|
||||
}
|
||||
|
||||
startCompilerElectron(port);
|
||||
})();
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
import { app, BrowserWindow, screen } from 'electron';
|
||||
import is_dev from 'electron-is-dev';
|
||||
import { join } from 'path';
|
||||
|
||||
let mainWindow: BrowserWindow | null = null;
|
||||
|
||||
class createWin {
|
||||
constructor() {
|
||||
const displayWorkAreaSize = screen.getAllDisplays()[0].workArea;
|
||||
mainWindow = new BrowserWindow({
|
||||
width: parseInt(`${displayWorkAreaSize.width * 0.85}`, 10),
|
||||
height: parseInt(`${displayWorkAreaSize.height * 0.85}`, 10),
|
||||
movable: true,
|
||||
// frame: false,
|
||||
show: false,
|
||||
center: true,
|
||||
resizable: true,
|
||||
// transparent: true,
|
||||
titleBarStyle: 'default',
|
||||
webPreferences: {
|
||||
devTools: true,
|
||||
contextIsolation: false,
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true,
|
||||
},
|
||||
backgroundColor: '#fff',
|
||||
});
|
||||
const URL = is_dev
|
||||
? `http://localhost:${process.env.PORT}` // vite 启动的服务器地址
|
||||
: `file://${join(__dirname, '../index.html')}`; // vite 构建后的静态文件地址
|
||||
|
||||
mainWindow.loadURL(URL);
|
||||
|
||||
mainWindow.on('ready-to-show', () => {
|
||||
mainWindow.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(() => new createWin());
|
||||
|
||||
const isFirstInstance = app.requestSingleInstanceLock();
|
||||
|
||||
if (!isFirstInstance) {
|
||||
app.quit();
|
||||
} else {
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
new createWin();
|
||||
}
|
||||
});
|
||||
57
package.json
57
package.json
|
|
@ -6,13 +6,56 @@
|
|||
"email": "anncwb@126.com",
|
||||
"url": "https://github.com/anncwb"
|
||||
},
|
||||
"main": "dist/main/build.js",
|
||||
"build": {
|
||||
"appId": "xxx@gmail.com",
|
||||
"electronDownload": {
|
||||
"mirror": "https://npm.taobao.org/mirrors/electron/"
|
||||
},
|
||||
"files": [
|
||||
"!node_modules",
|
||||
"dist/**"
|
||||
],
|
||||
"asar": false,
|
||||
"mac": {
|
||||
"artifactName": "${productName}_setup_${version}.${ext}",
|
||||
"target": [
|
||||
"dmg"
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"icon": "build/icons/512x512.png",
|
||||
"target": [
|
||||
"deb"
|
||||
]
|
||||
},
|
||||
"win": {
|
||||
"target": [
|
||||
{
|
||||
"target": "nsis",
|
||||
"arch": [
|
||||
"x64"
|
||||
]
|
||||
}
|
||||
],
|
||||
"artifactName": "${productName}_setup_${version}.${ext}"
|
||||
},
|
||||
"nsis": {
|
||||
"oneClick": false,
|
||||
"perMachine": false,
|
||||
"allowToChangeInstallationDirectory": true,
|
||||
"deleteAppDataOnUninstall": false
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"bootstrap": "yarn install",
|
||||
"serve": "npm run dev",
|
||||
"dev": "vite",
|
||||
"serve": "npm run dev",
|
||||
"build": "cross-env NODE_ENV=production vite build && esno ./build/script/postBuild.ts",
|
||||
"build:test": "cross-env vite build --mode test && esno ./build/script/postBuild.ts",
|
||||
"build:no-cache": "yarn clean:cache && npm run build",
|
||||
"dev:app": "esno ./build/script/startElectron.ts --env=development --watch",
|
||||
"build:app": "npm run build && esno ./build/script/startElectron.ts --env=production && electron-builder ",
|
||||
"report": "cross-env REPORT=true npm run build",
|
||||
"type:check": "vue-tsc --noEmit --skipLibCheck",
|
||||
"preview": "npm run build && vite preview",
|
||||
|
|
@ -43,6 +86,7 @@
|
|||
"axios": "^0.21.4",
|
||||
"codemirror": "^5.62.3",
|
||||
"cropperjs": "^1.5.12",
|
||||
"electron-is-dev": "^1.2.0",
|
||||
"crypto-js": "^4.1.1",
|
||||
"echarts": "^5.2.0",
|
||||
"intro.js": "^4.2.2",
|
||||
|
|
@ -70,6 +114,10 @@
|
|||
"@commitlint/config-conventional": "^13.1.0",
|
||||
"@iconify/json": "^1.1.401",
|
||||
"@purge-icons/generated": "^0.7.0",
|
||||
"@rollup/plugin-alias": "^3.1.1",
|
||||
"@rollup/plugin-commonjs": "^15.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^9.0.0",
|
||||
"@types/codemirror": "^5.60.2",
|
||||
"@types/crypto-js": "^4.0.2",
|
||||
"@types/fs-extra": "^9.0.12",
|
||||
|
|
@ -96,6 +144,11 @@
|
|||
"conventional-changelog-cli": "^2.1.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"dotenv": "^10.0.0",
|
||||
"electron": "^11.0.0",
|
||||
"electron-builder": "^22.8.0",
|
||||
"electron-connect": "^0.6.3",
|
||||
"electron-contextmenu-middleware": "^1.0.3",
|
||||
"electron-input-menu": "^2.1.0",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-define-config": "^1.0.9",
|
||||
|
|
@ -116,6 +169,7 @@
|
|||
"prettier": "^2.4.0",
|
||||
"pretty-quick": "^3.1.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup-plugin-esbuild": "^3.0.2",
|
||||
"rollup-plugin-visualizer": "5.5.2",
|
||||
"stylelint": "^13.13.1",
|
||||
"stylelint-config-prettier": "^8.0.2",
|
||||
|
|
@ -134,6 +188,7 @@
|
|||
"vite-plugin-style-import": "^1.2.1",
|
||||
"vite-plugin-svg-icons": "^1.0.4",
|
||||
"vite-plugin-theme": "^0.8.1",
|
||||
"wait-on": "^5.2.1",
|
||||
"vite-plugin-vue-setup-extend": "^0.1.0",
|
||||
"vite-plugin-windicss": "^1.4.2",
|
||||
"vue-eslint-parser": "^7.11.0",
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
|
|||
proxy: createProxy(VITE_PROXY),
|
||||
},
|
||||
build: {
|
||||
minify: 'esbuild',
|
||||
target: 'es2015',
|
||||
outDir: OUTPUT_DIR,
|
||||
terserOptions: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue