From ff9e6f537ace929b438f3901bf2cc17e517dc9f2 Mon Sep 17 00:00:00 2001 From: Matheusafonsouza Date: Sun, 8 Dec 2024 17:39:05 -0300 Subject: [PATCH] chore: add environment variable for backend --- .babelrc | 9 +++- .env.example | 1 + jest.config.ts | 3 ++ package-lock.json | 98 ++++++++++++++++++++++++++++++++++++++- package.json | 1 + src/config/environment.ts | 2 +- 6 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 .env.example diff --git a/.babelrc b/.babelrc index 673023f..a67b699 100644 --- a/.babelrc +++ b/.babelrc @@ -2,6 +2,13 @@ "presets": [ ["@babel/preset-env", { "targets": { "esmodules": true } }], // It's the name of the lib you installed ["@babel/preset-react", { "runtime": "automatic" }], // It's the name of the lib you installed - "@babel/preset-typescript" // It's the name of the lib you installed + "@babel/preset-typescript", // It's the name of the lib you installed + [ + "babel-preset-vite", + { + "env": true, + "glob": false + } + ] ] } diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..99cbcd5 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +VITE_API_BASE_URL=http://localhost:3000 diff --git a/jest.config.ts b/jest.config.ts index 0f88f24..b2a1bf3 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -17,4 +17,7 @@ export default { ], ], testMatch: ['/test/**/*.(test|spec).ts?(x)'], + transform: { + "^.+\\.[t|j]sx?$": "babel-jest", + }, }; diff --git a/package-lock.json b/package-lock.json index 38bd184..1ac0565 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39,6 +39,7 @@ "@typescript-eslint/parser": "^8.17.0", "@vitejs/plugin-react": "^4.3.3", "babel-jest": "^29.7.0", + "babel-preset-vite": "^1.1.3", "eslint": "^9.16.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-import": "^2.31.0", @@ -2176,7 +2177,7 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", - "extraneous": true, + "dev": true, "inBundle": true, "license": "MIT", "engines": { @@ -6113,6 +6114,87 @@ "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, + "node_modules/babel-plugin-transform-vite-meta-env": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-vite-meta-env/-/babel-plugin-transform-vite-meta-env-1.0.3.tgz", + "integrity": "sha512-eyfuDEXrMu667TQpmctHeTlJrZA6jXYHyEJFjcM0yEa60LS/LXlOg2PBbMb8DVS+V9CnTj/j9itdlDVMcY2zEg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.13.9", + "@types/babel__core": "^7.1.12" + } + }, + "node_modules/babel-plugin-transform-vite-meta-glob": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-vite-meta-glob/-/babel-plugin-transform-vite-meta-glob-1.1.2.tgz", + "integrity": "sha512-o984FUo++WYnfgUaC8ymzmNPng5Kda5A6j6PFC0uOqhFXlAsD6mNhEBhaNzbUGfq/aPcyeGo67fYXlg20rh9aA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.13.9", + "@types/babel__core": "^7.1.12", + "glob": "^10.3.10" + } + }, + "node_modules/babel-plugin-transform-vite-meta-glob/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/babel-plugin-transform-vite-meta-glob/node_modules/glob": { + "version": "10.4.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", + "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", + "dev": true, + "license": "ISC", + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^1.11.1" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/babel-plugin-transform-vite-meta-glob/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/babel-plugin-transform-vite-meta-hot": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-vite-meta-hot/-/babel-plugin-transform-vite-meta-hot-1.0.0.tgz", + "integrity": "sha512-qF7T46bDG5UPPOfy4MFgQJyd3mZvm1sGOR2gZ4lIHy6DEcxAVTIt39/adAn89il44CvwestshuEybKPMR+L/Tg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.13.9", + "@types/babel__core": "^7.1.12" + } + }, "node_modules/babel-preset-current-node-syntax": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.0.tgz", @@ -6157,6 +6239,20 @@ "@babel/core": "^7.0.0" } }, + "node_modules/babel-preset-vite": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/babel-preset-vite/-/babel-preset-vite-1.1.3.tgz", + "integrity": "sha512-xSt/EiezzeMd4RI2hjMCNyn/FGzGeroKODPMAUTsgpeHC4dFf2qiCQfyNuiNzn1OwoF4n+NYSsORhUN5G/2KTA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.13.9", + "@types/babel__core": "^7.1.12", + "babel-plugin-transform-vite-meta-env": "1.0.3", + "babel-plugin-transform-vite-meta-glob": "1.1.2", + "babel-plugin-transform-vite-meta-hot": "1.0.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", diff --git a/package.json b/package.json index 26f3a6d..3405db9 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "@typescript-eslint/parser": "^8.17.0", "@vitejs/plugin-react": "^4.3.3", "babel-jest": "^29.7.0", + "babel-preset-vite": "^1.1.3", "eslint": "^9.16.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-import": "^2.31.0", diff --git a/src/config/environment.ts b/src/config/environment.ts index 15fc6e5..1b098b1 100644 --- a/src/config/environment.ts +++ b/src/config/environment.ts @@ -1 +1 @@ -export const API_BASE_URL = 'http://localhost:3000'; +export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;