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

Feature: parsing env var in Vite #385

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions campus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@babel/preset-react": "7.16.7",
"@babel/preset-typescript": "7.16.7",
"@babel/runtime": "7.17.2",
"@types/node": "17.0.21",
"@types/systemjs": "6.1.1",
"@typescript-eslint/eslint-plugin": "5.14.0",
"@typescript-eslint/parser": "5.14.0",
Expand Down
6 changes: 6 additions & 0 deletions campus/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions campus/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import reactRefresh from "@vitejs/plugin-react-refresh";
import { defineConfig } from "vite";
import { defineConfig, loadEnv } from "vite";
import dynamicImport from "vite-plugin-dynamic-import";
const path = require("path");
const { parsed } = require("dotenv").config({
path: path.resolve(__dirname, "./src/.env"),
});

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const publicAssetsBaseUrl =
mode === "production"
? "/campus/"
: mode === "staging"
? `https://${parsed.MF_DOMAIN_WITH_PREFIX}/`
? `https://${env.MF_DOMAIN_WITH_PREFIX}/`
: "http://localhost:8081/";

return {
Expand Down
1 change: 1 addition & 0 deletions root/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@babel/preset-env": "7.16.11",
"@babel/preset-typescript": "7.16.7",
"@babel/runtime": "7.17.2",
"@types/node": "17.0.21",
"@types/systemjs": "6.1.1",
"@typescript-eslint/eslint-plugin": "5.14.0",
"@typescript-eslint/parser": "5.14.0",
Expand Down
596 changes: 329 additions & 267 deletions root/pnpm-lock.yaml

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions root/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
{
"imports": {
"@wasedatime/root-config": "/wasedatime-root-config.js",
"@wasedatime/syllabus": "https://<%= PREFIX %>.<%= MF_SYLLABUS_DOMAIN %>/wasedatime-syllabus.js",
"@wasedatime/campus": "https://<%= PREFIX %>.<%= MF_CAMPUS_DOMAIN %>/wasedatime-campus.js"
"@wasedatime/syllabus": "https://<%= env.PREFIX %>.<%= env.MF_SYLLABUS_DOMAIN %>/wasedatime-syllabus.js",
"@wasedatime/campus": "https://<%= env.PREFIX %>.<%= env.MF_CAMPUS_DOMAIN %>/wasedatime-campus.js"
}
}
</script>
<link rel="preload" href="https://<%= PREFIX %>.<%= MF_SYLLABUS_DOMAIN %>/assets/style.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="https://<%= PREFIX %>.<%= MF_SYLLABUS_DOMAIN %>/assets/style.css"></noscript>
<link rel="preload" href="https://<%= PREFIX %>.<%= MF_CAMPUS_DOMAIN %>/assets/style.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="https://<%= PREFIX %>.<%= MF_CAMPUS_DOMAIN %>/assets/style.css"></noscript>
<link rel="preload" href="https://<%= env.PREFIX %>.<%= env.MF_SYLLABUS_DOMAIN %>/assets/style.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="https://<%= env.PREFIX %>.<%= env.MF_SYLLABUS_DOMAIN %>/assets/style.css"></noscript>
<link rel="preload" href="https://<%= env.PREFIX %>.<%= env.MF_CAMPUS_DOMAIN %>/assets/style.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="https://<%= env.PREFIX %>.<%= env.MF_CAMPUS_DOMAIN %>/assets/style.css"></noscript>
<% } else { %>
<script type="importmap-shim" defer>
{
Expand Down
10 changes: 4 additions & 6 deletions root/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import reactRefresh from "@vitejs/plugin-react-refresh";
import dynamicImport from "vite-plugin-dynamic-import";
import { VitePWA } from "vite-plugin-pwa";
const path = require("path");
const { parsed } = require("dotenv").config({
path: path.resolve(__dirname, "./src/.env"),
});

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
return {
root: "./src",
publicDir: "assets",
Expand All @@ -34,8 +32,8 @@ export default defineConfig(({ mode }) => {
external:
mode === "staging"
? [
`https://${parsed.PREFIX}.${parsed.MF_SYLLABUS_DOMAIN}/assets/style.css`,
`https://${parsed.PREFIX}.${parsed.MF_CAMPUS_DOMAIN}/assets/style.css`,
`https://${env.PREFIX}.${env.MF_SYLLABUS_DOMAIN}/assets/style.css`,
`https://${env.PREFIX}.${env.MF_CAMPUS_DOMAIN}/assets/style.css`,
]
: mode === "production"
? ["/syllabus/assets/style.css", "/campus/assets/style.css"]
Expand All @@ -59,7 +57,7 @@ export default defineConfig(({ mode }) => {
isLocal: config.mode === "development",
isDev: config.mode === "staging",
standalone: false,
...parsed,
env,
})),
reactRefresh(),
dynamicImport(),
Expand Down
1 change: 1 addition & 0 deletions syllabus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@babel/preset-typescript": "7.16.7",
"@babel/runtime": "7.17.2",
"@semantic-ui-react/css-patch": "1.0.0",
"@types/node": "17.0.21",
"@types/react-s-alert": "^1.3.3",
"@types/systemjs": "6.1.1",
"@typescript-eslint/eslint-plugin": "5.14.0",
Expand Down
6 changes: 6 additions & 0 deletions syllabus/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions syllabus/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { defineConfig, loadEnv } from "vite";
import reactRefresh from "@vitejs/plugin-react-refresh";
import dynamicImport from "vite-plugin-dynamic-import";
const path = require("path");
const { parsed } = require("dotenv").config({
path: path.resolve(__dirname, "./src/.env"),
});

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const publicAssetsBaseUrl =
mode === "production"
? "/syllabus/"
: mode === "staging"
? `https://${parsed.MF_DOMAIN_WITH_PREFIX}/`
? `https://${env.MF_DOMAIN_WITH_PREFIX}/`
: "http://localhost:8080/";

return {
Expand Down