Skip to content

Instantly share code, notes, and snippets.

@timfish
Created June 16, 2021 23:44
Show Gist options
  • Save timfish/da446663e512e2e7f48660e2b76c552c to your computer and use it in GitHub Desktop.
Save timfish/da446663e512e2e7f48660e2b76c552c to your computer and use it in GitHub Desktop.
{
__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