This repository has been archived by the owner on Jan 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
127 lines (123 loc) · 4.01 KB
/
vite.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
123
124
125
126
127
import { partytownVite } from '@builder.io/partytown/utils';
import { qwikCity } from '@builder.io/qwik-city/vite';
import { qwikReact } from '@builder.io/qwik-react/vite';
import { qwikVite } from '@builder.io/qwik/optimizer';
import path, { resolve } from 'node:path';
import { defineConfig, loadEnv } from 'vite';
import { examplesData, playgroundData, tutorialData } from './vite.repl-apps';
import { sourceResolver } from './vite.source-resolver';
export default defineConfig(async () => {
const { default: rehypePrettyCode } = await import('rehype-pretty-code');
const routesDir = resolve('src', 'routes');
return {
dev: {
headers: {
'Cache-Control': 'public, max-age=0',
},
},
preview: {
headers: {
'Cache-Control': 'public, max-age=600',
},
},
resolve: {
alias: [
{
find: '~',
replacement: path.resolve(__dirname, 'src'),
},
],
},
ssr: {
noExternal: [
'@mui/material',
'@emotion/react',
],
},
plugins: [
qwikCity({
mdxPlugins: {
rehypeSyntaxHighlight: false,
remarkGfm: true,
rehypeAutolinkHeadings: true,
},
mdx: {
rehypePlugins: [
[
rehypePrettyCode as any,
{
theme: 'dark-plus',
onVisitLine(node: any) {
// Prevent lines from collapsing in `display: grid` mode, and
// allow empty lines to be copy/pasted
if (node.children.length === 0) {
node.children = [{ type: 'text', value: ' ' }];
}
},
onVisitHighlightedLine(node: any) {
// Each line node by default has `class="line"`.
if (node.properties.className) {
node.properties.className.push('line--highlighted');
}
},
onVisitHighlightedWord(node: any, id: string) {
// Each word node has no className by default.
node.properties.className = ['word'];
if (id) {
const backgroundColor = {
a: 'rgb(196 42 94 / 59%)',
b: 'rgb(0 103 163 / 56%)',
c: 'rgb(100 50 255 / 35%)',
}[id];
const color = {
a: 'rgb(255 225 225 / 100%)',
b: 'rgb(175 255 255 / 100%)',
c: 'rgb(225 200 255 / 100%)',
}[id];
if (node.properties['data-rehype-pretty-code-wrapper']) {
node.children.forEach((childNode: any) => {
childNode.properties.style = ``;
childNode.properties.className = '';
});
}
node.properties.style = `background-color: ${backgroundColor}; color: ${color};`;
}
},
},
],
],
},
}),
qwikVite(),
partytownVite({
dest: resolve('dist', '~partytown'),
}),
examplesData(routesDir),
playgroundData(routesDir),
tutorialData(routesDir),
sourceResolver(resolve('.')),
qwikReact(),
],
build: {
rollupOptions: {
// For some unknown reason, types don't work from tsc
// Try removing these any casts and see if it works
onLog(level: any, log: any, defaultHandler: any) {
if (level == 'warn' && log.code === 'MODULE_LEVEL_DIRECTIVE') {
// Suppress errors like these:
// FILE Module level directives cause errors when bundled, "use client" in FILE was ignored.
return;
}
defaultHandler(level, log);
},
output: {
assetFileNames: 'assets/[hash].[ext]',
},
},
},
clearScreen: false,
server: {
port: 3000,
},
};
});