forked from will-stone/browserosaurus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforge-externals-plugin.ts
68 lines (55 loc) · 1.67 KB
/
forge-externals-plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { PluginBase } from '@electron-forge/plugin-base'
import type {
ForgeHookMap,
ForgeMutatingHookFn,
} from '@electron-forge/shared-types'
interface Options {
externals: string[]
}
/**
* Required until @timfish/forge-externals-plugin updates to support getHooks
*/
class ForgeExternalsPlugin extends PluginBase<Options> {
public name = 'ForgeExternalsPlugin'
public externals: string[] = []
public constructor(options: Options) {
super(options)
this.externals = options.externals
this.getHooks = this.getHooks.bind(this)
}
public getHooks(): ForgeHookMap {
return {
resolveForgeConfig: this.resolveForgeConfig,
}
}
// eslint-disable-next-line require-await
private resolveForgeConfig: ForgeMutatingHookFn<'resolveForgeConfig'> =
async (forgeConfig) => {
const foundModules = new Set(this.externals)
// The webpack plugin already sets the ignore function.
const existingIgnoreFunction = forgeConfig.packagerConfig.ignore
// We override it and ensure we include external modules too
forgeConfig.packagerConfig.ignore = (file) => {
if (
typeof existingIgnoreFunction === 'function' &&
existingIgnoreFunction(file) === false
) {
return false
}
if (file === '/node_modules') {
return false
}
for (const module of foundModules) {
if (
file.startsWith(`/node_modules/${module}`) ||
file.startsWith(`/node_modules/${module.split('/')[0]}`)
) {
return false
}
}
return true
}
return forgeConfig
}
}
export default ForgeExternalsPlugin