generated from aws-samples/amplify-vite-react-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
57 lines (51 loc) · 1.47 KB
/
vite.config.ts
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
import { fileURLToPath } from "url";
import react from "@vitejs/plugin-react";
import { BuildOptions, ConfigEnv, defineConfig, loadEnv } from "vite";
// https://vitejs.dev/guide/api-javascript.html#resolvedconfig
const resolve = (destination: string) => {
return fileURLToPath(new URL("./" + destination, import.meta.url));
};
function hoistEnv(mode: string) {
// load the app level env variables and add them to the Node level env variables
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
}
const scopedName = "[hash:base64:5]";
const buildConfig = {
exclude: [resolve("./src/_DEV")],
} as BuildOptions;
// https://vitejs.dev/config/
export default ({ mode }: ConfigEnv) => {
hoistEnv(mode);
const port = parseInt(process.env.VITE_SUPER_CLIENT_PORT || "5173");
return defineConfig({
build: buildConfig,
css: {
modules: {
generateScopedName:
mode === "production"
? scopedName
: `[name]__[local]___${scopedName}`,
},
},
esbuild: {
logOverride: { "this-is-undefined-in-esm": "silent" },
},
plugins: [react()],
resolve: {
alias: [
{ find: "@", replacement: resolve(".") },
{ find: "_tw", replacement: resolve("./tailwindcss") },
],
},
server: {
watch: {
usePolling: true,
},
host: true, // needed for the Docker Container port mapping to work
hmr: {
clientPort: port,
},
port,
},
});
};