Skip to content

Commit

Permalink
fix: env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle committed Jan 29, 2024
1 parent 1efde89 commit 8b266f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/excalidraw/env.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const pkg = require("./package.json");
const parseEnvVariables = (filepath) => {
const envVars = Object.entries(dotenv.parse(readFileSync(filepath))).reduce(
(env, [key, value]) => {
env[key] = JSON.stringify(value);
env[key] = value;
return env;
},
{},
);
envVars.VITE_PKG_NAME = JSON.stringify(pkg.name);
envVars.VITE_PKG_VERSION = JSON.stringify(pkg.version);
envVars.VITE_IS_EXCALIDRAW_NPM_PACKAGE = JSON.stringify(true);
envVars.VITE_PKG_NAME = pkg.name;
envVars.VITE_PKG_VERSION = pkg.version;
envVars.VITE_IS_EXCALIDRAW_NPM_PACKAGE = true;
return envVars;
};

Expand Down
21 changes: 17 additions & 4 deletions scripts/buildPackage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { build } = require("esbuild");
const { sassPlugin } = require("esbuild-sass-plugin");
const { externalGlobalPlugin } = require("esbuild-plugin-external-global");
const { parseEnvVariables } = require("../packages/excalidraw/env.cjs");
// Will be used later for treeshaking
//const fs = require("fs");
// const path = require("path");
Expand Down Expand Up @@ -37,6 +38,17 @@ const { externalGlobalPlugin } = require("esbuild-plugin-external-global");
// return files;
// }

const ENV_VARS = {
development: {
...parseEnvVariables(`${__dirname}/../.env.development`),
DEV: true,
},
production: {
...parseEnvVariables(`${__dirname}/../.env.production`),
PROD: true,
},
};

const browserConfig = {
entryPoints: ["index.tsx"],
bundle: true,
Expand All @@ -54,6 +66,7 @@ const browserConfig = {
".ttf": "copy",
},
};

const createESMBrowserBuild = async () => {
// Development unminified build with source maps
await build({
Expand All @@ -62,7 +75,7 @@ const createESMBrowserBuild = async () => {
sourcemap: true,
chunkNames: "excalidraw-assets-dev/[name]-[hash]",
define: {
"import.meta.env": JSON.stringify({ DEV: true }),
"import.meta.env": JSON.stringify(ENV_VARS.development),
},
});

Expand All @@ -73,7 +86,7 @@ const createESMBrowserBuild = async () => {
minify: true,
chunkNames: "excalidraw-assets/[name]-[hash]",
define: {
"import.meta.env": JSON.stringify({ PROD: true }),
"import.meta.env": JSON.stringify(ENV_VARS.production),
},
});
};
Expand Down Expand Up @@ -116,7 +129,7 @@ const createESMRawBuild = async () => {
sourcemap: true,
outdir: "dist/dev",
define: {
"import.meta.env": JSON.stringify({ DEV: true }),
"import.meta.env": JSON.stringify(ENV_VARS.development),
},
});

Expand All @@ -126,7 +139,7 @@ const createESMRawBuild = async () => {
minify: true,
outdir: "dist/prod",
define: {
"import.meta.env": JSON.stringify({ PROD: true }),
"import.meta.env": JSON.stringify(ENV_VARS.production),
},
});
};
Expand Down

0 comments on commit 8b266f2

Please sign in to comment.