-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathtsup.config.ts
122 lines (115 loc) · 2.9 KB
/
tsup.config.ts
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
import { defineConfig } from 'tsup';
import { writeFileSync, readFileSync } from 'fs';
import { join, resolve } from 'path';
export default defineConfig({
entry: ['src/pages/web/index.tsx'],
format: ['esm'],
dts: true,
splitting: true,
sourcemap: false,
clean: true,
treeshake: true,
minify: true,
env: {
BUILD_TARGET: 'web',
NODE_ENV: 'production',
},
external: [
'react',
'react-dom',
],
esbuildOptions(options) {
options.bundle = true;
options.platform = 'browser';
options.loader = {
'.css': 'css',
'.scss': 'css',
'.svg': 'dataurl',
'.png': 'dataurl',
'.jpg': 'dataurl',
},
options.alias = {
'@': resolve(__dirname, './src')
}
options.external = [
'@tauri-apps/api',
'@tauri-apps/plugin-*',
'tauri-plugin-*',
];
options.treeShaking = true;
options.define = {
'process.env.BUILD_TARGET': '"web"',
'process.env.NODE_ENV': '"production"',
'process.env.DEBUG': 'false',
'process.env.IS_DEV': 'false',
};
options.pure = ['console.log'];
options.target = 'es2020';
options.legalComments = 'none';
options.ignoreAnnotations = false;
},
esbuildPlugins: [
{
name: 'jsx-import-source',
setup(build) {
build.initialOptions.jsx = 'automatic';
build.initialOptions.jsxImportSource = 'react';
},
},
],
outDir: 'out/search-chat',
async onSuccess() {
const projectPackageJson = JSON.parse(
readFileSync(join(__dirname, 'package.json'), 'utf-8')
);
const packageJson = {
name: "@infinilabs/search-chat",
version: "1.0.10",
main: "index.js",
module: "index.js",
type: "module",
types: "index.d.ts",
dependencies: projectPackageJson.dependencies,
peerDependencies: {
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"sideEffects": [
"*.css",
"*.scss"
],
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
};
const noNeedDeps = [
"@wavesurfer/react",
"dotenv",
"uuid",
"wavesurfer.js",
]
const tauriDeps = Object.keys(packageJson.dependencies).filter(dep =>
dep.includes('@tauri-apps') ||
dep.includes('tauri-plugin') ||
noNeedDeps.includes(dep)
);
tauriDeps.forEach(dep => {
delete packageJson.dependencies[dep];
});
writeFileSync(
join(__dirname, 'out/search-chat/package.json'),
JSON.stringify(packageJson, null, 2)
);
try {
const readmePath = join(__dirname, 'src/pages/web/README.md');
const readmeContent = readFileSync(readmePath, 'utf-8');
writeFileSync(
join(__dirname, 'out/search-chat/README.md'),
readmeContent
);
} catch (error) {
console.error('Failed to copy README.md:', error);
}
}
});