Skip to content

Commit 80976d8

Browse files
committed
feat: 添加PWA配置
1 parent 2e05325 commit 80976d8

12 files changed

Lines changed: 373 additions & 19 deletions
File renamed without changes.
File renamed without changes.

public/images/icons/icon.svg

Lines changed: 296 additions & 0 deletions
Loading
36.7 KB
Loading
3.11 KB
Loading
12.8 KB
Loading
1.36 KB
Loading

rsbuild.config.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { execSync } from 'node:child_process';
2+
import { readFile, writeFile } from 'node:fs/promises';
3+
import path from 'node:path';
24
import { GenerateSW } from '@aaroon/workbox-rspack-plugin';
3-
import { defineConfig } from '@rsbuild/core';
5+
import { defineConfig, type RsbuildPlugin } from '@rsbuild/core';
46
import { pluginBabel } from '@rsbuild/plugin-babel';
57
import { pluginSass } from '@rsbuild/plugin-sass';
68
import { pluginSolid } from '@rsbuild/plugin-solid';
@@ -31,7 +33,8 @@ export default defineConfig({
3133
pluginSass(),
3234
],
3335
html: {
34-
template: './src/index.browser.html',
36+
template: './src/index.html',
37+
title: '',
3538
},
3639
output: {
3740
polyfill: 'usage',
@@ -50,7 +53,7 @@ export default defineConfig({
5053
port: process.env.NODE_ENV === 'development' ? 3000 : 8080,
5154
publicDir: false,
5255
},
53-
tools: {},
56+
5457
source: {
5558
define: {
5659
IS_TAURI: false,
@@ -85,6 +88,22 @@ export default defineConfig({
8588
],
8689
},
8790
},
91+
plugins: [
92+
{
93+
name: 'web-manifest-plugin',
94+
setup(api) {
95+
api.onBeforeBuild(async () => {
96+
const { rootPath, distPath } = api.context;
97+
const manifest = await readFile(path.join(rootPath, './src/manifest.json'), { encoding: 'utf-8' });
98+
const replacedManifest = manifest.replaceAll(
99+
'<%= process.env.BASE_URL %>',
100+
api.getRsbuildConfig('current').output.assetPrefix,
101+
);
102+
await writeFile(path.join(distPath, 'manifest.json'), replacedManifest);
103+
});
104+
},
105+
} satisfies RsbuildPlugin,
106+
],
88107
},
89108
tauri: {
90109
output: {
@@ -99,10 +118,6 @@ export default defineConfig({
99118
CONFIG_ENABLE_PWA: false,
100119
},
101120
},
102-
html: {
103-
template: './src/index.tauri.html',
104-
title: '',
105-
},
106121
},
107122
},
108123
});
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
<html>
33
<head>
44
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<% if (!IS_TAURI) { %>
57
<title>快照凭证打印助手</title>
68
<meta name="description" content="将多个转账记录图、电商订单图等以凭证样式打印到纸中。" />
79
<meta name="keywords" content="快照凭证打印助手, 快照凭证打印, 快照凭证, 截图凭证, 截图打印" />
810
<link rel="icon" type="image/png" href="<%= process.env.BASE_URL %>favicon-96x96.png" sizes="96x96" />
911
<link rel="icon" type="image/svg+xml" href="<%= process.env.BASE_URL %>favicon.svg" />
1012
<link rel="shortcut icon" href="<%= process.env.BASE_URL %>favicon.ico" />
11-
<link rel="apple-touch-icon" sizes="180x180" href="<%= process.env.BASE_URL %>images/apple-touch-icon.png" />
13+
<link rel="apple-touch-icon" sizes="180x180" href="<%= process.env.BASE_URL %>images/icons/apple-touch-icon.png" />
1214
<meta name="apple-mobile-web-app-title" content="快照凭证打印助手" />
13-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
15+
<link rel="manifest" href="<%= process.env.BASE_URL %>manifest.json" />
16+
<% } %>
1417
</head>
1518
<body>
1619
<div id="<%= mountId %>"></div>

0 commit comments

Comments
 (0)