-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvite.config.js
117 lines (108 loc) · 3.57 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
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
/*-------------------------------------------------------------------------------------------------
* Copyright (C) 2024 Intel Corporation. All rights reserved.
* Licensed under the Apache License 2.0. See LICENSE in the project root for license information.
* SPDX-License-Identifier: Apache-2.0
*-----------------------------------------------------------------------------------------------*/
import { defineConfig } from "vite";
import basicSsl from "@vitejs/plugin-basic-ssl";
import { existsSync } from "fs";
import * as path from "path";
import topLevelAwait from "vite-plugin-top-level-await";
function resourceHandlerPlugin() {
return {
name: "resource-handler-plugin",
configureServer(server) {
const base = server.config.base || "/";
return () => {
server.middlewares.use((req, res, next) => {
// Set HSTS header for secure connections
if (req.secure) {
// max-age is the time in seconds that the browser should remember that the site is only to be accessed using HTTPS
// includeSubDomains ensures that the rule applies to all subdomains as well
res.setHeader(
"Strict-Transport-Security",
"max-age=31536000; includeSubDomains"
);
}
// if request the local static resource
if (req.originalUrl.startsWith(base)) {
const localPath = req.originalUrl.replace(base, "");
const localFilePath = path.join(__dirname, localPath);
if (!existsSync(localFilePath)) {
res.setHeader("Content-Type", "text/html");
res.statusCode = 404;
res.end("Not Found");
return;
}
}
next();
});
};
}
};
}
export default () => {
return defineConfig({
// define the global variable
define: {
VITE_ENV_USE_REMOTE_MODELS: process.argv
.slice(2)
.includes(`use-remote-models`)
? true
: false
},
base: "./",
optimizeDeps: {
esbuildOptions: {
target: "esnext"
}
},
server: {
fallback: false,
host: "0.0.0.0",
https: true
},
build: {
target: "esnext",
rollupOptions: {
input: {
main: path.resolve(__dirname, "index.html"),
terms: path.resolve(__dirname, "terms.html"),
stable_diffusion: path.resolve(
__dirname,
"samples/stable_diffusion/stable-diffusion.html"
),
llm_gemma: path.resolve(__dirname, "samples/llm_gemma/gemma.html"),
image_background_removal: path.resolve(
__dirname,
"samples/image_background_removal/index.html"
),
image_to_text: path.resolve(
__dirname,
"samples/image_to_text/index.html"
),
summarization: path.resolve(
__dirname,
"samples/summarization/index.html"
),
question_answering: path.resolve(
__dirname,
"samples/question_answering/index.html"
),
worker: path.resolve(__dirname, "samples/common/worker.js")
}
}
},
worker: {
plugins: () => [
topLevelAwait({
// The export name of top-level await promise for each chunk module
promiseExportName: "__tla",
// The function to generate import names of top-level await promise in each chunk module
promiseImportName: (i) => `__tla_${i}`
})
]
},
plugins: [basicSsl(), resourceHandlerPlugin()]
});
};