fix: package env vars (#9221)
This commit is contained in:
parent
d92384b77d
commit
70c3e921bb
@ -4,14 +4,14 @@ const pkg = require("./package.json");
|
|||||||
const parseEnvVariables = (filepath) => {
|
const parseEnvVariables = (filepath) => {
|
||||||
const envVars = Object.entries(dotenv.parse(readFileSync(filepath))).reduce(
|
const envVars = Object.entries(dotenv.parse(readFileSync(filepath))).reduce(
|
||||||
(env, [key, value]) => {
|
(env, [key, value]) => {
|
||||||
env[key] = JSON.stringify(value);
|
env[key] = value;
|
||||||
return env;
|
return env;
|
||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
envVars.VITE_PKG_NAME = JSON.stringify(pkg.name);
|
envVars.VITE_PKG_NAME = pkg.name;
|
||||||
envVars.VITE_PKG_VERSION = JSON.stringify(pkg.version);
|
envVars.VITE_PKG_VERSION = pkg.version;
|
||||||
envVars.VITE_IS_EXCALIDRAW_NPM_PACKAGE = JSON.stringify(true);
|
envVars.VITE_IS_EXCALIDRAW_NPM_PACKAGE = true;
|
||||||
return envVars;
|
return envVars;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ export class ExcalidrawFontFace {
|
|||||||
|
|
||||||
private static readonly ASSETS_FALLBACK_URL = `https://esm.sh/${
|
private static readonly ASSETS_FALLBACK_URL = `https://esm.sh/${
|
||||||
import.meta.env.VITE_PKG_NAME
|
import.meta.env.VITE_PKG_NAME
|
||||||
? `${import.meta.env.VITE_PKG_NAME}@${import.meta.env.PKG_VERSION}` // should be provided by vite during package build
|
? `${import.meta.env.VITE_PKG_NAME}@${import.meta.env.VITE_PKG_VERSION}` // should be provided by vite during package build
|
||||||
: "@excalidraw/excalidraw" // fallback to latest package version (i.e. for app)
|
: "@excalidraw/excalidraw" // fallback to latest package version (i.e. for app)
|
||||||
}/dist/prod/`;
|
}/dist/prod/`;
|
||||||
|
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { build } = require("esbuild");
|
const { build } = require("esbuild");
|
||||||
const { sassPlugin } = require("esbuild-sass-plugin");
|
const { sassPlugin } = require("esbuild-sass-plugin");
|
||||||
|
const { parseEnvVariables } = require("../packages/excalidraw/env.cjs");
|
||||||
|
|
||||||
|
const ENV_VARS = {
|
||||||
|
development: {
|
||||||
|
...parseEnvVariables(`${__dirname}/../.env.development`),
|
||||||
|
DEV: true,
|
||||||
|
},
|
||||||
|
production: {
|
||||||
|
...parseEnvVariables(`${__dirname}/../.env.production`),
|
||||||
|
PROD: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// excludes all external dependencies and bundles only the source code
|
// excludes all external dependencies and bundles only the source code
|
||||||
const getConfig = (outdir) => ({
|
const getConfig = (outdir) => ({
|
||||||
@ -28,7 +40,7 @@ function buildDev(config) {
|
|||||||
...config,
|
...config,
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
define: {
|
define: {
|
||||||
"import.meta.env": JSON.stringify({ DEV: true }),
|
"import.meta.env": JSON.stringify(ENV_VARS.development),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -38,7 +50,7 @@ function buildProd(config) {
|
|||||||
...config,
|
...config,
|
||||||
minify: true,
|
minify: true,
|
||||||
define: {
|
define: {
|
||||||
"import.meta.env": JSON.stringify({ PROD: true }),
|
"import.meta.env": JSON.stringify(ENV_VARS.production),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user