-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.mts
50 lines (46 loc) · 1.44 KB
/
vite.config.mts
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
import { defineConfig, PluginOption } from 'vite';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
// https://github.com/MarkEdit-app/MarkEdit/wiki/Customization
const MARKEDIT_SCRIPTS_DIR = '/Library/Containers/app.cyan.markedit/Data/Documents/scripts/';
const BUILD_OUT_DIR = 'dist';
const copyDistFile: PluginOption = {
name: 'copy-dist-file',
closeBundle: () => {
const distDir = path.join(__dirname, BUILD_OUT_DIR);
const filename = fs.readdirSync(distDir).find(name => path.extname(name) === '.js');
if (filename === undefined) {
console.error('Failed to find generated .js file in dist directory.');
return;
}
const sourcePath = path.join(distDir, filename);
const destPath = path.join(os.userInfo().homedir, MARKEDIT_SCRIPTS_DIR, filename);
fs.copyFileSync(sourcePath, destPath);
console.log(`Successfully deployed: ${filename}, run "yarn reload" to restart the app.`);
}
}
export default defineConfig({
build: {
outDir: BUILD_OUT_DIR,
rollupOptions: {
external: [
'markedit-api',
'@codemirror/view',
'@codemirror/state',
'@codemirror/language',
'@codemirror/commands',
'@codemirror/search',
'@lezer/common',
'@lezer/highlight',
'@lezer/markdown',
'@lezer/lr',
],
},
lib: {
entry: 'main.ts',
formats: ['cjs'],
},
},
plugins: [copyDistFile],
});