2021-10-25 00:12:02 +00:00
|
|
|
import react from "@vitejs/plugin-react";
|
2021-10-11 09:30:02 +00:00
|
|
|
import { defineConfig, loadEnv } from "vite";
|
|
|
|
import eslintPlugin from "vite-plugin-eslint";
|
2021-10-08 04:00:06 +00:00
|
|
|
import istanbul from "vite-plugin-istanbul";
|
|
|
|
import svgr from "vite-plugin-svgr";
|
|
|
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
|
|
|
2021-10-11 09:30:02 +00:00
|
|
|
// @ts-ignore
|
2021-10-08 04:00:06 +00:00
|
|
|
export default defineConfig(({ mode }) => {
|
2022-04-05 05:43:52 +00:00
|
|
|
const env = loadEnv(mode, ".");
|
2021-10-11 09:30:02 +00:00
|
|
|
const isCoverage = process.env.VITE_COVERAGE === "true";
|
|
|
|
const sourcemap = isCoverage ? "inline" : undefined;
|
2021-10-08 04:00:06 +00:00
|
|
|
|
2021-10-11 09:30:02 +00:00
|
|
|
const htmlPlugin = () => {
|
|
|
|
return {
|
|
|
|
name: "html-transform",
|
|
|
|
transformIndexHtml(html: string) {
|
|
|
|
return html.replace(/%(.*?)%/g, function (match, p1) {
|
|
|
|
return env[p1];
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
2021-10-08 04:00:06 +00:00
|
|
|
|
2021-10-11 09:30:02 +00:00
|
|
|
const istanbulPlugin = isCoverage
|
|
|
|
? istanbul({
|
|
|
|
include: "src/*",
|
|
|
|
exclude: ["node_modules"],
|
|
|
|
extension: [".js", ".jsx", ".ts", ".tsx"],
|
2021-10-20 23:15:15 +00:00
|
|
|
checkProd: false,
|
2022-05-02 04:03:09 +00:00
|
|
|
forceBuildInstrument: true,
|
2021-10-11 09:30:02 +00:00
|
|
|
requireEnv: true,
|
|
|
|
})
|
|
|
|
: undefined;
|
2021-10-08 04:00:06 +00:00
|
|
|
|
|
|
|
return {
|
2021-10-11 09:30:02 +00:00
|
|
|
base: "./",
|
2021-10-08 04:00:06 +00:00
|
|
|
build: {
|
|
|
|
sourcemap,
|
|
|
|
outDir: "../internal/server/public_html",
|
2022-04-04 02:55:09 +00:00
|
|
|
emptyOutDir: true,
|
2021-10-08 04:00:06 +00:00
|
|
|
assetsDir: "static",
|
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
entryFileNames: `static/js/[name].[hash].js`,
|
|
|
|
chunkFileNames: `static/js/[name].[hash].js`,
|
2021-10-11 09:30:02 +00:00
|
|
|
assetFileNames: ({ name }) => {
|
|
|
|
if (name && name.endsWith(".css")) {
|
|
|
|
return "static/css/[name].[hash].[ext]";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "static/media/[name].[hash].[ext]";
|
|
|
|
},
|
2021-10-08 04:00:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
server: {
|
|
|
|
open: false,
|
|
|
|
hmr: {
|
|
|
|
clientPort: env.VITE_HMR_PORT || 3000,
|
|
|
|
},
|
|
|
|
},
|
2021-12-01 03:32:58 +00:00
|
|
|
plugins: [eslintPlugin({ cache: false }), htmlPlugin(), istanbulPlugin, react(), svgr(), tsconfigPaths()],
|
2021-10-08 04:00:06 +00:00
|
|
|
};
|
|
|
|
});
|