Skip to content

Commit e9d28e4

Browse files
authored
Merge pull request #170 from johnb8/webpack-electron-fix
Webpack electron fix
2 parents c6e8c2a + d14435a commit e9d28e4

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ const loader = function AppConfigLoader(this: Loader) {
4444
4545
const globalNamespace = (typeof window === 'undefined' ? globalThis : window) || {};
4646
47-
// if the global was already defined, use it (and define it if not)
48-
const config = globalNamespace.${privateName} =
49-
(globalNamespace.${privateName} || configValue);
47+
// if the global was already defined, use it
48+
const config = (globalNamespace.${privateName} || configValue);
49+
50+
// 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
51+
if (!Object.isFrozen(globalNamespace.${privateName})) {
52+
globalNamespace.${privateName} = config;
53+
}
5054
5155
export { config };
5256
export default config;

0 commit comments

Comments
 (0)