-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite-snippet-min.config.ts
44 lines (42 loc) · 1.17 KB
/
vite-snippet-min.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
import { resolve } from 'path';
import { defineConfig, PluginOption } from 'vite';
import { copyFileSync, readdirSync } from 'fs';
import { version } from './package.json';
const outDir = 'dist-snippet';
function cloneAsLatest(): PluginOption {
return {
name: 'clone-as-latest',
closeBundle() {
try {
readdirSync(outDir).forEach((fileName) => {
const latest = fileName
.replace(/^(\d+\.\d+\.\d+)/, 'latest')
.replace(/-\w*\.\d+/, '-rc');
copyFileSync(`${outDir}/${fileName}`, `${outDir}/${latest}`);
});
console.log('\n✓ iife snippet cloned as latest');
} catch (err: any) {
console.error(`\n❗️iife snippet wasn't cloned as latest`, err);
process.exit(err?.errno || -1);
}
},
};
}
export default defineConfig({
plugins: [cloneAsLatest()],
define: {
__APP_VERSION__: JSON.stringify(version),
},
build: {
emptyOutDir: false,
outDir,
minify: true,
sourcemap: true,
lib: {
entry: resolve(__dirname, 'lib/snippet/index.ts'),
name: '__unused__',
formats: ['iife'],
fileName: () => `${version}.min.js`,
},
},
});