-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
84 lines (79 loc) · 2.15 KB
/
vite.config.js
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
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import path from 'path';
import { readMarkdownFile, loadCache } from './src/lib/utilities/index';
import mri from 'mri';
const args = mri(process.argv);
const demoDir = process.cwd() + '/content';
const NPMRunDev = process.argv[2] === 'dev';
const isBuild = process.argv[2] === 'build';
const receivedHomePath = NPMRunDev || isBuild ? false : args.directory;
const homeDir = receivedHomePath || demoDir;
const $home = [homeDir];
export default defineConfig({
plugins: [
sveltekit(),
{
// Hot reload markdown
name: 'markdown:watch',
configureServer(server) {
server.watcher.add(homeDir);
server.watcher.on('add', () => {
server.ws.send('vowel:refresh');
});
server.watcher.on('unlink', () => {
server.ws.send('vowel:refresh');
});
server.watcher.on('change', async (homePath, stats) => {
if (homePath.endsWith('.md')) {
// Remove `.md`
const cache = await loadCache(homeDir);
const file = await readMarkdownFile(homePath, cache);
Object.assign(file, file.frontmatter);
const relativePath = path
.relative(homeDir, homePath)
.slice(0, -3)
.replace(/\/?(home)$/, '')
.replace(/\/?(settings)$/, '_');
server.ws.send('vowel:update', {
path: relativePath,
stats,
file
});
}
});
}
}
],
define: { $home },
optimizeDeps: {
exclude: ['svelte', 'remark', 'remark-frontmatter', 'remark-html'],
include: [
'micromark',
'unified',
'fault',
'url-metadata',
'any-date-parser',
'any-date-parser/src/formats/ago/ago.js',
'any-date-parser/src/formats/ago/ago.js',
'any-date-parser/src/formats/chinese/chinese.js',
'any-date-parser/src/formats/dayMonth/dayMonth.js',
'any-date-parser/src/formats/dayMonthname/dayMonthname.js',
'any-date-parser/src/formats/monthDay/monthDay.js',
'any-date-parser/src/formats/monthnameDay/monthnameDay.js',
'any-date-parser/src/formats/today/today.js'
]
},
server: {
fs: {
strict: false,
allow: homeDir
},
hmr: {
overlay: false
}
},
resolve: {
// extensions: ['.css']
}
});