Skip to content

Commit d14435a

Browse files
committed
fix: make vite and rollup plugins compatible with electron package
1 parent 5fb7e5f commit d14435a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

app-config-rollup/src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export interface Options {
1111
schemaLoadingOptions?: SchemaLoadingOptions;
1212
}
1313

14+
const privateName = '_appConfig';
15+
1416
// vite resolves first before passing to the rollup plugin
1517
export const appConfigImportRegex = /(app-config|app-config-main)\/dist(\/es)?\/index\.js/;
1618

@@ -53,9 +55,13 @@ export default function appConfigRollup({
5355
5456
const globalNamespace = (typeof window === 'undefined' ? globalThis : window) || {};
5557
56-
// if the global was already defined, use it (and define it if not)
57-
const config = globalNamespace._appConfig =
58-
(globalNamespace._appConfig || configValue);
58+
// if the global was already defined, use it
59+
const config = (globalNamespace.${privateName} || configValue);
60+
61+
// if the global is frozen then it was set by electron and we can't change it, but we'll set it if we can
62+
if (!Object.isFrozen(globalNamespace.${privateName})) {
63+
globalNamespace.${privateName} = config;
64+
}
5965
`;
6066
} else {
6167
generatedText = `

app-config-webpack/src/loader.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const loader = function AppConfigLoader(this: Loader) {
5252
globalNamespace.${privateName} = config;
5353
}
5454
55-
5655
export { config };
5756
export default config;
5857
`;

0 commit comments

Comments
 (0)