-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrsbuild.config.ts
More file actions
125 lines (121 loc) · 3.22 KB
/
rsbuild.config.ts
File metadata and controls
125 lines (121 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { execSync } from 'node:child_process';
import { GenerateSW } from '@aaroon/workbox-rspack-plugin';
import { defineConfig, type RsbuildPlugin } from '@rsbuild/core';
import { pluginBabel } from '@rsbuild/plugin-babel';
import { pluginSass } from '@rsbuild/plugin-sass';
import { pluginSolid } from '@rsbuild/plugin-solid';
const GIT_REFERENCE =
process.env.NODE_ENV === 'development'
? 'main'
: (() => {
try {
return execSync('git describe --tags --exact-match HEAD').toString().trim();
} catch (_e) {
console.warn('Failed to get git tags, using commit hash instead');
try {
return execSync('git rev-parse HEAD').toString().trim();
} catch (_e) {
console.warn('Failed to get git commit hash');
return 'main';
}
}
})();
export default defineConfig({
plugins: [
pluginBabel({
include: /\.(?:jsx|tsx)$/,
}),
pluginSolid(),
pluginSass(),
],
html: {
template: './src/index.html',
title: '',
},
output: {
polyfill: 'usage',
minify: {
jsOptions: {
minimizerOptions: {
compress: {
passes: 4,
},
},
},
css: true,
},
},
server: {
port: process.env.NODE_ENV === 'development' ? 3000 : 8080,
publicDir: false,
},
source: {
define: {
IS_TAURI: false,
CONFIG_ENABLE_PWA: true,
'import.meta.env.GIT_REFERENCE': JSON.stringify(GIT_REFERENCE),
'import.meta.env.APP_VERSION': JSON.stringify(process.env.npm_package_version),
},
},
performance: {
removeConsole: ['log'],
},
environments: {
browser: {
output: {
distPath: {
root: 'dist/browser',
},
copy: [{ from: './public', to: '.' }],
},
tools: {
rspack: {
plugins: [
...(process.env.NODE_ENV === 'development'
? []
: [
new GenerateSW({
cacheId: 'snap-proof-print-helper',
cleanupOutdatedCaches: true,
}),
]),
],
},
},
plugins: [
{
name: 'web-manifest-plugin',
setup(api) {
api.processAssets({ stage: 'additional' }, async ({ sources, compilation }) => {
const manifest = await import('./manifest.json');
delete manifest.$schema;
const localeManifest = (await import('./localizedManifest')).default;
const mergedManifest = Object.assign(manifest, localeManifest);
const source = new sources.RawSource(
JSON.stringify(mergedManifest).replaceAll(
'<%= process.env.BASE_URL %>',
api.getRsbuildConfig('current').output.assetPrefix,
),
);
compilation.emitAsset('manifest.json', source);
});
},
} satisfies RsbuildPlugin,
],
},
tauri: {
output: {
distPath: {
root: 'dist/tauri',
},
copy: [],
},
source: {
define: {
IS_TAURI: true,
CONFIG_ENABLE_PWA: false,
},
},
},
},
});