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