forked from preactjs/preact-www
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
114 lines (110 loc) Β· 3.09 KB
/
vite.config.js
File metadata and controls
114 lines (110 loc) Β· 3.09 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
import { defineConfig } from 'vite';
import preact from '@preact/preset-vite';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import path from 'path';
import { precompileMarkdown } from './plugins/precompile-markdown/index.js';
import { netlifyPlugin } from './plugins/netlify.js';
import { spaFallbackMiddlewarePlugin } from './plugins/spa-fallback-middleware.js';
import { htmlRoutingMiddlewarePlugin } from './plugins/html-routing-middleware.js';
import { rssFeedPlugin } from './plugins/rss-feed.js';
import generateLlmsTxtPlugin from './plugins/generate-llms-txt.js';
import {
headerNav,
flatDocPages,
tutorialPages,
blogPosts
} from './src/route-config.js';
/**
* @param {'v8' | 'v10' | 'v11'} version
* @param {string} path
* @returns {string}
*/
const flatDocPathToNested = (version, path) => `/guide/${version}${path}`;
export default defineConfig({
publicDir: 'src/assets',
optimizeDeps: {
include: ['@babel/polyfill', '@rollup/browser', 'sucrase']
},
build: {
target: ['chrome88', 'edge88', 'es2020', 'firefox78', 'safari14'],
outDir: 'build',
rollupOptions: {
output: {
chunkFileNames: chunkInfo => {
if (chunkInfo.moduleIds.find(id => id.includes('@xmldom/xmldom')))
return 'assets/xmldom-[hash].js';
if (chunkInfo.facadeModuleId?.includes('@docsearch/react'))
return 'assets/docsearch-[hash].js';
return 'assets/[name]-[hash].js';
}
}
}
},
define: {
'process.env.BRANCH': JSON.stringify(process.env.BRANCH)
},
plugins: [
preact({
prerender: {
enabled: true,
renderTarget: '#app',
// The routes that will not be discovered automatically
additionalPrerenderRoutes: [
'/404',
'/branding',
...Object.keys(headerNav),
...Object.keys(flatDocPages.v8).map(path =>
flatDocPathToNested('v8', path)
),
...Object.keys(flatDocPages.v10).map(path =>
flatDocPathToNested('v10', path)
),
...Object.keys(flatDocPages.v11).map(path =>
flatDocPathToNested('v11', path)
),
...Object.keys(tutorialPages),
...Object.keys(blogPosts)
]
}
}),
viteStaticCopy({
hook: 'generateBundle',
targets: [
{
src: './content/**/*.md',
dest: './',
rename: (_name, _fileExtension, fullPath) =>
path.basename(fullPath).replace(/\.md$/, '.json'),
transform: precompileMarkdown
}
],
structured: true,
watch: {
reloadPageOnChange: true
}
}),
viteStaticCopy({
// Safari will always request both `apple-touch-icon.png` and
// `apple-touch-icon-precomposed.png` regardless of any set path via `<link>`
// tags. The latter serves no purpose since iOS 7.0, but as Safari still
// requests it, we may as well provide it to get this out of our 404 stats.
targets: [
{
src: './src/assets/app-icon.png',
dest: './',
rename: 'apple-touch-icon.png'
},
{
src: './src/assets/app-icon.png',
dest: './',
rename: 'apple-touch-icon-precomposed.png'
}
]
}),
netlifyPlugin(),
spaFallbackMiddlewarePlugin(),
htmlRoutingMiddlewarePlugin(),
rssFeedPlugin(),
generateLlmsTxtPlugin()
]
});