Skip to content

Commit

Permalink
Fixed vite config not reading env file
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker committed Sep 2, 2024
1 parent d65c6ee commit 13011b3
Showing 1 changed file with 90 additions and 86 deletions.
176 changes: 90 additions & 86 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import react from "@vitejs/plugin-react-swc";
import checker from "vite-plugin-checker";
import { viteStaticCopy } from "vite-plugin-static-copy";
import { treeShakeCareIcons } from "./plugins/treeShakeCareIcons";
import { loadEnv } from "vite";

const pdfWorkerPath = path.join(
path.dirname(
Expand All @@ -23,105 +24,108 @@ const cdnUrls =
].join(" ");

/** @type {import('vite').UserConfig} */
export default {
envPrefix: "REACT_",
plugins: [
viteStaticCopy({
targets: [
{
src: pdfWorkerPath,
dest: "",
},
],
}),
react(),
checker({ typescript: true }),
treeShakeCareIcons({
iconWhitelist: ["default"],
}),
VitePWA({
strategies: "injectManifest",
srcDir: "src",
filename: "service-worker.ts",
injectRegister: "script-defer",
devOptions: {
enabled: true,
type: "module",
},
injectManifest: {
maximumFileSizeToCacheInBytes: 7000000,
},
manifest: {
name: "Care",
short_name: "Care",
theme_color: "#0e9f6e",
background_color: "#ffffff",
display: "standalone",
icons: [
{
src: "images/icons/pwa-64x64.png",
sizes: "64x64",
type: "image/png",
},
{
src: "images/icons/pwa-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "images/icons/pwa-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "any",
},
export default ({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd(), '') };
return {
envPrefix: "REACT_",
plugins: [
viteStaticCopy({
targets: [
{
src: "images/icons/maskable-icon-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
src: pdfWorkerPath,
dest: "",
},
],
},
}),
],
build: {
outDir: "build",
assetsDir: "bundle",
sourcemap: true,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes("node_modules")) {
return "vendor";
}
}),
react(),
checker({ typescript: true }),
treeShakeCareIcons({
iconWhitelist: ["default"],
}),
VitePWA({
strategies: "injectManifest",
srcDir: "src",
filename: "service-worker.ts",
injectRegister: "script-defer",
devOptions: {
enabled: true,
type: "module",
},
injectManifest: {
maximumFileSizeToCacheInBytes: 7000000,
},
manifest: {
name: "Care",
short_name: "Care",
theme_color: "#0e9f6e",
background_color: "#ffffff",
display: "standalone",
icons: [
{
src: "images/icons/pwa-64x64.png",
sizes: "64x64",
type: "image/png",
},
{
src: "images/icons/pwa-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "images/icons/pwa-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "any",
},
{
src: "images/icons/maskable-icon-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
},
}),
],
build: {
outDir: "build",
assetsDir: "bundle",
sourcemap: true,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes("node_modules")) {
return "vendor";
}
},
},
},
},
},
server: {
port: 4000,
proxy: {
"/api": {
target: process.env.CARE_API ?? "https://careapi.ohc.network",
changeOrigin: true,
server: {
port: 4000,
proxy: {
"/api": {
target: process.env.CARE_API ?? "https://careapi.ohc.network",
changeOrigin: true,
},
},
},
},
preview: {
headers: {
"Content-Security-Policy-Report-Only": `default-src 'self';\
preview: {
headers: {
"Content-Security-Policy-Report-Only": `default-src 'self';\
script-src 'self' blob: 'nonce-f51b9742' https://plausible.10bedicu.in;\
style-src 'self' 'unsafe-inline';\
connect-src 'self' https://plausible.10bedicu.in;\
img-src 'self' https://cdn.ohc.network ${cdnUrls};\
object-src 'self' ${cdnUrls};`,
},
port: 4000,
proxy: {
"/api": {
target: process.env.CARE_API ?? "https://careapi.ohc.network",
changeOrigin: true,
},
port: 4000,
proxy: {
"/api": {
target: process.env.CARE_API ?? "https://careapi.ohc.network",
changeOrigin: true,
},
},
},
},
}
};

0 comments on commit 13011b3

Please sign in to comment.