Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed vite config not reading env file #8465

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
},
},
},
}
};
Loading