Skip to content

Commit d71d95e

Browse files
author
xiaotian
committed
配置打包
1 parent 865a018 commit d71d95e

12 files changed

+175
-83
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# production
1111
/dist
12+
/build
1213

1314
# misc
1415
.DS_Store

.umirc.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { defineConfig } from 'umi';
2-
import WindiCSSWebpackPlugin from 'windicss-webpack-plugin'
2+
import WindiCSSWebpackPlugin from 'windicss-webpack-plugin';
33

44
export default defineConfig({
5-
outputPath: 'app/build',
5+
history: {
6+
type: 'hash',
7+
},
8+
publicPath: './',
9+
outputPath: './build',
610
nodeModulesTransform: {
711
type: 'none',
812
},
9-
routes: [
10-
{ path: '/', component: '@/pages/index' },
11-
],
13+
routes: [{ path: '/', component: '@/pages/index' }],
1214
fastRefresh: {},
1315
chainWebpack(memo, { env, webpack, createCSSRule }) {
14-
memo.plugin('windicss').use(WindiCSSWebpackPlugin)
15-
}
16+
memo.plugin('windicss').use(WindiCSSWebpackPlugin);
17+
},
1618
});

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ umijs + electron
77
```
88
yarn start:app
99
```
10+
## 打包
11+
1. 先使用yarn build打包umi项目
12+
2. 再使用`yarn build:mac-app``yarn build:win-app`打包electron应用
1013
## 截图
1114
![](./imgs/[email protected])
1215
![](./imgs/[email protected])

app-entry.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
2+
const path = require('path');
3+
const fs = require('fs');
4+
5+
const isPro = process.env.NODE_ENV !== 'development';
6+
function renderWindow() {
7+
const mainWindow = new BrowserWindow({
8+
width: 750,
9+
height: 550,
10+
webPreferences: {
11+
nodeIntegration: true,
12+
contextIsolation: false,
13+
// preload: path.resolve(__dirname, 'preload.js')
14+
},
15+
});
16+
17+
if (isPro) {
18+
mainWindow.loadURL(
19+
require('url').format({
20+
pathname: path.join(__dirname, 'build/index.html'),
21+
protocol: 'file:',
22+
slashes: true,
23+
}),
24+
);
25+
} else {
26+
mainWindow.loadURL('http://localhost:8000/');
27+
// 打开开发者工具,默认不打开
28+
mainWindow.webContents.openDevTools();
29+
}
30+
31+
ipcMain.on('read-laihuo-excel', async (evt) => {
32+
const { filePaths } = await dialog.showOpenDialog({
33+
filters: [
34+
{
35+
name: 'Excel',
36+
extensions: ['xlsx'],
37+
},
38+
],
39+
});
40+
evt.reply(
41+
'read-laihuo-success',
42+
filePaths[0],
43+
fs.readFileSync(filePaths[0]),
44+
);
45+
});
46+
ipcMain.on('read-fahuo-excel', async (evt) => {
47+
const { filePaths } = await dialog.showOpenDialog({
48+
filters: [
49+
{
50+
name: 'Excel',
51+
extensions: ['xlsx'],
52+
},
53+
],
54+
});
55+
evt.reply(
56+
'read-fahuo-success',
57+
filePaths[0],
58+
fs.readFileSync(filePaths[0]),
59+
);
60+
});
61+
}
62+
63+
app.whenReady().then(() => {
64+
renderWindow();
65+
app.on('activate', function () {
66+
if (BrowserWindow.getAllWindows().length === 0) renderWindow();
67+
});
68+
});
69+
70+
app.on('window-all-closed', () => {
71+
if (process.platform === 'darwin') return;
72+
73+
app.quit();
74+
});

app/main.ts

-56
This file was deleted.

electron-builder.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
appId: kucun_sys
2+
publish:
3+
provider: github
4+
token: tt
5+
directories:
6+
output: release/
7+
buildResources: build

package.json

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
11
{
2+
"name": "kucun_sys",
3+
"version": "1.0.0",
4+
"main": "app-entry.js",
5+
"author": {
6+
"name": "xtwan",
7+
"email": "[email protected]"
8+
},
9+
"description": "库存管理应用",
210
"private": true,
311
"scripts": {
4-
"start:app": "concurrently \"cross-env BROWSER=none yarn start\" \"wait-on http://localhost:8000 && cross-env NODE_ENV=development electron app/main.ts\"",
12+
"start:app": "concurrently \"cross-env BROWSER=none yarn start\" \"wait-on http://localhost:8000 && cross-env NODE_ENV=development electron app-entry.js\"",
513
"start": "umi dev",
614
"build": "umi build",
15+
"build:mac-app": "electron-builder --mac --x64",
16+
"build:win-app": "electron-builder --win --x64",
717
"postinstall": "umi generate tmp",
818
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
919
"test": "umi-test",
1020
"test:coverage": "umi-test --coverage"
1121
},
22+
"build": {
23+
"appId": "com.xtwan.app",
24+
"mac": {
25+
"target": [
26+
"dmg",
27+
"zip"
28+
]
29+
},
30+
"win": {
31+
"target": [
32+
"nsis",
33+
"zip"
34+
]
35+
},
36+
"files": [
37+
"build/**/*",
38+
"app-entry.js"
39+
]
40+
},
1241
"gitHooks": {
1342
"pre-commit": "lint-staged"
1443
},
@@ -35,6 +64,8 @@
3564
"concurrently": "^6.4.0",
3665
"cross-env": "^7.0.3",
3766
"electron": "^16.0.1",
67+
"electron-builder": "^22.14.5",
68+
"express": "^4.17.1",
3869
"lint-staged": "^10.0.7",
3970
"prettier": "^2.2.0",
4071
"typescript": "^4.1.2",

serve.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* 起服务:将打包后的代码运行在服务之上 */
2+
let express = require('express');
3+
/* process是全局变量无需引入 */
4+
let port = 80;
5+
6+
let app = express();
7+
8+
/* Express框架:提供了static中间件来设置静态文件的资源 */
9+
app.use(express.static('./app/build'));
10+
11+
/* 起端口 */
12+
module.exports = app.listen(port, function (err) {
13+
if (err) {
14+
console.log(err);
15+
return;
16+
}
17+
console.log('Listening at http://localhost:' + port + '\n');
18+
});

src/app.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
import 'windi.css'
1+
import 'windi.css';
2+
3+
console.log('app test');

src/pages/index.tsx

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
import { Steps } from 'antd'
2-
import { useState, createContext } from 'react'
3-
import UploadData from '@/component/upload-data'
4-
import DataPreview from '@/component/data-preview'
1+
import { Steps } from 'antd';
2+
import { useState, createContext } from 'react';
3+
import UploadData from '@/component/upload-data';
4+
import DataPreview from '@/component/data-preview';
55

6-
export const Ctx = createContext({} as {
7-
setLaihuoFile: (file: ArrayBuffer) => void
8-
setFahuoFile: (file: ArrayBuffer) => void
9-
setColorMap: (map: Record<string, string>) => void
10-
})
6+
export const Ctx = createContext(
7+
{} as {
8+
setLaihuoFile: (file: ArrayBuffer) => void;
9+
setFahuoFile: (file: ArrayBuffer) => void;
10+
setColorMap: (map: Record<string, string>) => void;
11+
},
12+
);
1113
export default function IndexPage() {
12-
const [step, setStep] = useState(0)
13-
const [laihuoFile, setLaihuoFile] = useState<ArrayBuffer>()
14-
const [fahuoFile, setFahuoFile] = useState<ArrayBuffer>()
15-
const [colorMap, setColorMap] = useState<Record<string, string>>()
14+
console.log('test index');
15+
const [step, setStep] = useState(0);
16+
const [laihuoFile, setLaihuoFile] = useState<ArrayBuffer>();
17+
const [fahuoFile, setFahuoFile] = useState<ArrayBuffer>();
18+
const [colorMap, setColorMap] = useState<Record<string, string>>();
1619
function handleNextStep() {
17-
setStep(step + 1)
20+
setStep(step + 1);
1821
}
1922
function handleReUpload() {
20-
setStep(0)
23+
setStep(0);
2124
}
2225

2326
return (
@@ -27,9 +30,16 @@ export default function IndexPage() {
2730
<Steps.Step title="上传表格"></Steps.Step>
2831
<Steps.Step title="结果预览"></Steps.Step>
2932
</Steps>
30-
{
31-
step === 0 ? <UploadData nextStep={handleNextStep} /> : <DataPreview reupload={handleReUpload} colorMap={colorMap!} laihuoFile={laihuoFile!} fahuoFile={fahuoFile!} />
32-
}
33+
{step === 0 ? (
34+
<UploadData nextStep={handleNextStep} />
35+
) : (
36+
<DataPreview
37+
reupload={handleReUpload}
38+
colorMap={colorMap!}
39+
laihuoFile={laihuoFile!}
40+
fahuoFile={fahuoFile!}
41+
/>
42+
)}
3343
</div>
3444
</Ctx.Provider>
3545
);
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)