-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.js
86 lines (78 loc) · 2.4 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
85
86
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import fastGlob from 'fast-glob';
import tsconfigPaths from 'vite-tsconfig-paths'
import unpluginMarkdown2Html from 'unplugin-markdown-2-html/vite'
const mdDirectoryImportPlugin = () => {
const virtualModuleId = 'virtual:mddir:';
const resolvedVirtualModuleId = '\0' + virtualModuleId;
return {
name: 'md-dir-import',
async resolveId(source, importer) {
if (source.startsWith(virtualModuleId)) {
const relativeDirPath = source.slice(virtualModuleId.length);
const resolveDir = importer ? path.dirname(importer) : process.cwd();
return resolvedVirtualModuleId + path.resolve(resolveDir, relativeDirPath);
}
return null;
},
async load(id) {
if (id.startsWith(resolvedVirtualModuleId)) {
id = id.slice(resolvedVirtualModuleId.length);
const files = await fastGlob(`${id}.md`, {
cwd: path.dirname(id),
});
const parsedFiles = files.map(file => {
const lang = /\.en\.md$/.test(file) ? 'EN' : 'FR';
const key = [
path.basename(file, ".md"),
path.basename(file, ".en.md"),
path.basename(file, ".fr.md"),
].reduce((next, str) => next.length < str.length ? next : str) + '_' + lang;
return { key, file };
});
const contents = `
${files.map((file, index) => `import { html as __policy_html_${index} } from '${file}';`).join('\n')}
export const html = {
${parsedFiles.map(({ key }, index) => `${key}: __policy_html_${index}`).join(',')}
};
`;
return contents;
}
return null;
}
};
};
export default defineConfig({
plugins: [
mdDirectoryImportPlugin(),
unpluginMarkdown2Html({
anchor: { level: 6 }
}),
react(),
tsconfigPaths(),
],
assetsInclude: ['**/*.json'],
build: {
outDir: 'www/',
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
},
entryFileNames: 'assets/[name].[hash].js',
chunkFileNames: 'assets/[name].[hash].js',
assetFileNames: 'assets/[name].[hash].[ext]',
},
},
minify: 'terser',
sourcemap: 'hidden',
target: 'esnext',
compress: true,
},
define: {
'window.IS_PRODUCTION': true,
},
logLevel: 'info',
});