-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
58 lines (54 loc) · 1.69 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
58
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react-swc";
import { resolve } from "path";
import { existsSync, readFileSync } from "fs";
import * as dotenv from "dotenv";
import postCssConfig from "./postcss.config";
import svgr from "vite-plugin-svgr";
import mdx from "@mdx-js/rollup";
import macrosPlugin from "vite-plugin-babel-macros";
// import { PALETTE } from "./tailwind.config";
const envPath = ".env";
export default ({ mode }) => {
process.env = loadEnv(mode, process.cwd(), ""); // <-- #sec-sensitive do not expose to compiled app
const appEnv = existsSync(envPath)
? dotenv.parse(readFileSync(envPath, { encoding: "utf8" }))
: {}; // <-- .env only
return defineConfig({
css: {
postcss: {
plugins: postCssConfig.plugins,
},
},
plugins: [
{ enforce: "pre", ...mdx() },
react(/*{ include: /\.(mdx|js|jsx|ts|tsx)$/ }*/),
macrosPlugin(),
svgr(),
/*{
name: "markdown-loader",
transform(code, id) {
if (id.slice(-3) === ".md") {
// For .md files, get the raw content
return `export default ${JSON.stringify(code)};`;
}
}
}*/
],
publicDir: "./static",
assetsInclude: ["**/*.md"],
define: {
global: "globalThis",
__version__: JSON.stringify(process.env.npm_package_version),
"process.env": appEnv,
// COLORS_PALETTE: PALETTE,
},
resolve: {
alias: [
{ find: "@/static", replacement: resolve(__dirname, "./static") },
{ find: "~", replacement: resolve(__dirname, "./src") },
{ find: "@", replacement: resolve(__dirname, "./src") },
],
},
});
};