Created
June 16, 2021 23:44
-
-
Save timfish/da446663e512e2e7f48660e2b76c552c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
__isElectronForgePlugin: true, | |
async init() { | |
// | |
}, | |
getHook(hookName) { | |
switch (hookName) { | |
case "resolveForgeConfig": | |
return this.resolveForgeConfig; | |
} | |
}, | |
async resolveForgeConfig(forgeConfig) { | |
const externals = ["native-hello-world"]; | |
const modules = new Set(externals); | |
for (const external of externals) { | |
const moduleRoot = dirname( | |
require.resolve(`${external}/package.json`) | |
); | |
const walker = new Walker(moduleRoot); | |
(await walker.walkTree()) | |
.filter((dep) => dep.nativeModuleType === DepType.PROD) | |
.map((dep) => dep.name) | |
.forEach((name) => modules.add(name)); | |
} | |
const existingFn = forgeConfig.packagerConfig.ignore; | |
forgeConfig.packagerConfig.ignore = (file) => { | |
const existingResult = existingFn(file); | |
if (existingResult == false) { | |
return false; | |
} | |
if (file === "/node_modules") { | |
return false; | |
} | |
for (const module of modules) { | |
if (file.startsWith(`/node_modules/${module}`)) { | |
console.log(file, false); | |
return false; | |
} | |
} | |
return true; | |
}; | |
return forgeConfig; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment