coder/site/vite.config.ts

98 lines
3.2 KiB
TypeScript
Raw Permalink Normal View History

import react from "@vitejs/plugin-react";
import path from "path";
import { visualizer } from "rollup-plugin-visualizer";
import { defineConfig, type PluginOption } from "vite";
import checker from "vite-plugin-checker";
2023-01-18 17:31:31 +00:00
2023-05-05 21:46:51 +00:00
const plugins: PluginOption[] = [
react(),
checker({
typescript: true,
}),
];
2023-01-18 17:31:31 +00:00
if (process.env.STATS !== undefined) {
plugins.push(
visualizer({
filename: "./stats/index.html",
}),
);
2023-01-18 17:31:31 +00:00
}
export default defineConfig({
2023-01-18 17:31:31 +00:00
plugins: plugins,
publicDir: path.resolve(__dirname, "./static"),
build: {
outDir: path.resolve(__dirname, "./out"),
2022-09-28 16:11:00 +00:00
// We need to keep the /bin folder and GITKEEP files
emptyOutDir: false,
// 'hidden' works like true except that the corresponding sourcemap comments in the bundled files are suppressed
sourcemap: "hidden",
},
define: {
2022-09-28 16:11:00 +00:00
"process.env": {
NODE_ENV: process.env.NODE_ENV,
STORYBOOK: process.env.STORYBOOK,
INSPECT_XSTATE: process.env.INSPECT_XSTATE,
2022-09-28 16:11:00 +00:00
},
},
server: {
host: "127.0.0.1",
port: process.env.PORT ? Number(process.env.PORT) : 8080,
headers: {
// This header corresponds to "src/api/api.ts"'s hardcoded FE token.
// This is the secret side of the CSRF double cookie submit method.
// This should be sent on **every** response from the webserver.
//
// This is required because in production, the Golang webserver generates
// this "Set-Cookie" header. The Vite webserver needs to replicate this
// behavior. Instead of implementing CSRF though, we just use static
// values for simplicity.
"Set-Cookie":
"csrf_token=JXm9hOUdZctWt0ZZGAy9xiS/gxMKYOThdxjjMnMUyn4=; Path=/; HttpOnly; SameSite=Lax",
},
proxy: {
"/api": {
ws: true,
changeOrigin: true,
target: process.env.CODER_HOST || "http://localhost:3000",
secure: process.env.NODE_ENV === "production",
configure: (proxy) => {
// Vite does not catch socket errors, and stops the webserver.
// As /logs endpoint can return HTTP 4xx status, we need to embrace
// Vite with a custom error handler to prevent from quitting.
proxy.on("proxyReqWs", (proxyReq, req, socket) => {
if (process.env.NODE_ENV === "development") {
proxyReq.setHeader(
"origin",
process.env.CODER_HOST || "http://localhost:3000",
);
}
socket.on("error", (error) => {
console.error(error);
});
});
},
},
feat: Build framework for generating API docs (#5383) * WIP * Gen * WIP * chi swagger * WIP * WIP * WIP * GetWorkspaces * GetWorkspaces * Markdown * Use widdershins * WIP * WIP * WIP * Markdown template * Fix: makefile * fmt * Fix: comment * Enable swagger conditionally * fix: site * Default false * Flag tests * fix * fix * template fixes * Fix * Fix * Fix * WIP * Formatted * Cleanup * Templates * BEGIN END SECTION * subshell exit code * Fix * Fix merge * WIP * Fix * Fix fmt * Fix * Generic api.md page * Fix merge * Link pages * Fix * Fix * Fix: links * Add icon * Write manifest file * Fix fmt * Fix: enterprise * Fix: Swagger.Enable * Fix: rename apidocs to apidoc * Fix: find -not -prune * Fix: json not available * Fix: rename Coderd API to Coder API * Fix: npm exec * Fix: api dir * Fix: by ID * Fix: string uuid * Fix: include deleted * Fix: indirect go.mod * Fix: source lib.sh * Fix: shellcheck * Fix: pushd popd * Fix: fmt * Fix: improve workspaces * Fix: swagger-enable * Fix * Fix: mention only HTTP 200 * Fix: IDs * Fix: https * Fix: icon * More APis * Fix: format swagger.json * Fix: SwaggerEndpoint * Fix: SCRIPT_DIR * Fix: PROJECT_ROOT * Fix: use code tags in schemas.md * Fix: examples * Fix: examples * Fix: improve format * Fix: date-time,enums * Fix: include_deleted * Fix: array of * Fix: parameter, response * Fix: string time or null * Workspaces: more docs * Workspaces: more docs * Fix: renderDisplayName * Fix: ActiveUserCount * Fix * Fix: typo * Templates: docs * Notice: incomplete
2022-12-19 17:43:46 +00:00
"/swagger": {
target: process.env.CODER_HOST || "http://localhost:3000",
secure: process.env.NODE_ENV === "production",
},
},
},
resolve: {
alias: {
api: path.resolve(__dirname, "./src/api"),
components: path.resolve(__dirname, "./src/components"),
contexts: path.resolve(__dirname, "./src/contexts"),
hooks: path.resolve(__dirname, "./src/hooks"),
modules: path.resolve(__dirname, "./src/modules"),
pages: path.resolve(__dirname, "./src/pages"),
testHelpers: path.resolve(__dirname, "./src/testHelpers"),
theme: path.resolve(__dirname, "./src/theme"),
utils: path.resolve(__dirname, "./src/utils"),
},
},
});