-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathvite.config.js
More file actions
46 lines (44 loc) · 1.59 KB
/
Copy pathvite.config.js
File metadata and controls
46 lines (44 loc) · 1.59 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
import { defineConfig } from 'vite';
// One per `vite build` invocation. Stamps the classic-script URLs in
// index.html below so the browser can tell two deploys' upload.js
// apart even though the path itself never changes.
const buildId = Date.now().toString(36);
export default defineConfig({
// Relative asset URLs so the built site works both at the root of
// compare.sitespeed.io and when mounted under a sub-path (e.g. the
// onlinetest server serves a vendored copy at `/compare/`).
base: './',
// Anything in public/ is served at the site root verbatim, with the
// same paths in dev and production. Used for the classic compare
// scripts (which share globals via window).
publicDir: 'public',
plugins: [
{
// The Vite-emitted assets in /assets/ are already content-hashed
// (filename changes when content changes). The classic compare
// scripts in public/js/ are served at stable URLs — without help
// they'd sit in browser caches across deploys. This plugin
// appends ?v=<buildId> to those src URLs at build time so each
// deploy invalidates the cache for its classic-script set.
name: 'version-classic-scripts',
apply: 'build',
transformIndexHtml(html) {
// base: './' rewrites root-relative paths to `./` form, so
// match either shape.
return html.replace(
/src="((?:\.\/|\/)js\/[^"?]+\.js)"/g,
'src="$1?v=' + buildId + '"'
);
}
}
],
build: {
outDir: 'dist',
emptyOutDir: true
},
server: {
port: 3000,
strictPort: false,
open: false
}
});