-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathvite.config.ts
More file actions
49 lines (47 loc) · 1.6 KB
/
Copy pathvite.config.ts
File metadata and controls
49 lines (47 loc) · 1.6 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
import { readFile } from 'node:fs/promises'
import path from 'node:path'
import { defineConfig } from 'vite'
const artifactSafetyPageRE = /(?:^|\/)ssr-plugin-safety[.]md$/
export default defineConfig({
publicDir: process.env.VITE_TEST_SSR_PLUGIN_PARITY
? 'batch-public'
: undefined,
resolve: process.env.VITE_TEST_SSR_PLUGIN_PARITY
? {
alias: {
'/vitepress.png': path.resolve(
import.meta.dirname,
'public/vitepress.png'
)
}
}
: undefined,
plugins: [
{
name: 'test:config-file-artifact-safety',
apply: 'build',
applyToEnvironment(environment) {
const environmentName = environment.name
return {
name: `test:resolved-artifact-safety:${environmentName}`,
enforce: 'pre',
load: {
filter: { id: artifactSafetyPageRE },
async handler(id) {
const source = await readFile(id, 'utf8')
return `${source}\n<p data-resolved-load-environment="${environmentName}">physical Markdown load hook</p>`
}
},
transform: {
filter: { id: artifactSafetyPageRE },
handler(code, _id, options) {
const mode = options?.ssr ? 'server' : 'client'
const pluginContext = `${this.environment.mode}:${this.meta.watchMode}`
return `${code}\n<p data-resolved-transform-mode="${mode}">environment-sensitive Markdown transform</p>\n<p data-resolved-plugin-context="${pluginContext}">production plugin context</p>`
}
}
}
}
}
]
})