authelia/web/vite.config.ts
Amir Zarrinkafsh a3e84769b5
feat(web): replace cra with vite (#2457)
* feat(web): replace cra with vite

* fix: add istanbul
* fix: add jest
* fix: inject env vars
* fix: replicate cra output directories
* fix: post-frontend build for go templating
* fix: dynamic publicpath

* fix(web): import resolution with aliases for .module.css files

* refactor(server): baseurl var

* refactor(web): drop babel-jest for esbuild-jest

* refactor(web): add inline sourcemap for coverage bundle

* build(deps): update web deps

* build(deps): downgrade vite-plugin-istanbul to 2.2.0

98bf77dbaa is a breaking change that means production mode builds can no longer be instrumented.

* refactor(web): match frontend name and version

* refactor(web): drop cra readme
2021-10-08 15:00:06 +11:00

70 lines
1.9 KiB
TypeScript

import path from "path";
import { loadEnv } from "vite";
import istanbul from "vite-plugin-istanbul";
import svgr from "vite-plugin-svgr";
import { defineConfig } from "vite-react";
import tsconfigPaths from "vite-tsconfig-paths";
const isCoverage = process.env.VITE_COVERAGE === "true";
const istanbulPlugin = isCoverage
? istanbul({
include: "src/*",
exclude: ["node_modules"],
extension: [".js", ".jsx", ".ts", ".tsx"],
requireEnv: true,
})
: undefined;
const sourcemap = isCoverage ? "inline" : undefined;
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, "env");
function assetOutput(name: string | undefined) {
if (name && name.endsWith(".css")) {
return "static/css/[name].[hash].[ext]";
}
return "static/media/[name].[hash].[ext]";
}
return {
build: {
sourcemap,
outDir: "../internal/server/public_html",
assetsDir: "static",
rollupOptions: {
output: {
entryFileNames: `static/js/[name].[hash].js`,
chunkFileNames: `static/js/[name].[hash].js`,
assetFileNames: ({ name }) => assetOutput(name),
},
},
},
envDir: "env",
eslint: {
enable: true,
},
html: {
injectData: {
...env,
},
},
server: {
open: false,
hmr: {
clientPort: env.VITE_HMR_PORT || 3000,
},
},
resolve: {
alias: [
{
find: "@components",
replacement: path.resolve(__dirname, "src/components"),
},
],
},
plugins: [istanbulPlugin, svgr(), tsconfigPaths()],
};
});