-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvite.config.ts
More file actions
193 lines (168 loc) · 5.07 KB
/
vite.config.ts
File metadata and controls
193 lines (168 loc) · 5.07 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import { defineConfig } from 'vite';
import { cemPluginDefaultOptions } from '@gracile-labs/jsx/vite';
import { generateLitTypes } from '@gracile-labs/jsx/cem/index';
import { literalsHtmlCssMinifier } from '@literals/rollup-plugin-html-css-minifier';
import manifest from '@shoelace-style/shoelace/dist/custom-elements.json' with { type: 'json' };
import Inspect from 'vite-plugin-inspect';
import { gracile } from '@gracile/gracile/plugin';
import { marked } from 'marked';
import markedShiki from 'marked-shiki';
import { litShikiLanguages } from '@gracile/doc/lib/markdown-old/tm-grammars/lit.js';
import { createHighlighter, type ShikiTransformer } from 'shiki';
// import {
// transformerNotationDiff,
// transformerNotationHighlight,
// transformerNotationWordHighlight,
// transformerNotationFocus,
// transformerNotationErrorLevel,
// transformerMetaHighlight,
// transformerMetaWordHighlight,
// } from '@shikijs/transformers';
import terser from '@rollup/plugin-terser';
// import { babel } from '@rollup/plugin-babel';
// FIXME:
// import babelPluginProposalDecorators from '@babel/plugin-proposal-decorators';
// import babelPluginSyntaxTypescript from '@babel/plugin-syntax-typescript';
// import strip from '@rollup/plugin-strip';
// import vue from '@vitejs/plugin-vue';
// import react from '@vitejs/plugin-react';
// import { svelte } from '@sveltejs/vite-plugin-svelte';
import { viteMarkdownPlugin } from '@gracile/markdown/vite';
import { MarkdownRenderer } from '@gracile/markdown-preset-marked';
import * as common from './vite.common.js';
// import { viteStaticCopy } from 'vite-plugin-static-copy';
import { customElementsManifestToMarkdown } from '@custom-elements-manifest/to-markdown';
import fs from 'fs';
generateLitTypes(manifest, {
...cemPluginDefaultOptions,
fileName: 'jsx-vendor.d.ts',
});
function generateCemDocs() {
const manifest = JSON.parse(
fs.readFileSync('./dist/custom-elements.json', 'utf-8'),
);
const markdown = customElementsManifestToMarkdown(manifest, {
private: 'hidden',
omitDeclarations: [
'mixins',
'variables',
'functions',
'exports',
'super-class',
],
omitSections: ['mixins', 'super-class'],
// headingOffset: 0,
// private: 'details',
});
fs.writeFileSync('./custom-elements.md', markdown);
}
generateCemDocs();
export default defineConfig(async ({ mode }) => {
console.log("'Mode", mode);
return {
server: { watch: { usePolling: false } },
resolve: common.resolve,
build: {
target: 'esnext',
sourcemap: true,
outDir: 'dist-site',
},
plugins: [
common.babelConfig,
Inspect(),
common.gracileJsxConfig,
gracile(),
common.staticCopy(mode),
// viteStaticCopy({
// targets: [
// {
// src: 'docs',
// dest: 'api',
// },
// ],
// }),
await mdConfig(),
mode === 'production' ? terser() : null,
mode === 'production' ? literalsHtmlCssMinifier() : null,
// vue(),
// react({ exclude: ['**/*.el.*'] }),
// svelte(),
],
};
});
const highlighter = await createHighlighter({
langs: [
'md',
'js',
'ts',
'tsx',
'vue',
'sh',
'css',
'scss',
...litShikiLanguages,
],
themes: ['github-dark-default'],
});
function transformerFileNames(): ShikiTransformer {
return {
line(hast) {
const comment = '// @filename: ';
const fileNameCommentLine = hast.children.find(
(e) =>
e?.type === 'element' &&
e?.children?.some(
(e2) => e2?.type === 'text' && e2?.value?.startsWith(comment),
),
);
if (fileNameCommentLine?.type === 'element') {
const elem = fileNameCommentLine.children.at(0);
if (elem?.type !== 'text') return;
const value = elem.value.replace(comment, '');
hast.tagName = 'div';
hast.properties = { class: 'file-title' };
hast.children = [{ type: 'text', value }];
}
},
};
}
async function mdConfig() {
const _marked = marked
// .use({
// walkTokens() {},
// })
.use(
markedShiki({
highlight(code, lang, props) {
// console.log(code, lang);
return highlighter.codeToHtml(code, {
lang,
theme: 'github-dark-default',
meta: { __raw: props.join(' ') }, // required by `transformerMeta*`
transformers: [
// transformerNotationDiff(),
// transformerNotationHighlight(),
// transformerNotationWordHighlight(),
// transformerNotationFocus(),
// transformerNotationErrorLevel(),
// transformerMetaHighlight(),
// transformerMetaWordHighlight(),
transformerFileNames(),
],
});
},
}),
);
return [
viteMarkdownPlugin({
MarkdownRenderer,
options: {
markedInstance: _marked,
collectCodeBlocks: true,
post(infos) {
// console.log({ infos });
},
},
}),
];
}