UNPKG

2.52 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ExternalsPlugin } from "webpack";
3
4export = webpackNodeExternals;
5
6type GetArrayInnerType<T> = T extends Array<infer U> ? U : never;
7/** The webpack types don't export this so we have to derive it. */
8type ExternalItem = GetArrayInnerType<ExternalsPlugin["externals"]>;
9
10declare function webpackNodeExternals(options?: webpackNodeExternals.Options): ExternalItem;
11
12declare namespace webpackNodeExternals {
13 type AllowlistOption = string | RegExp | AllowlistFunctionType;
14 type ImportTypeCallback = (moduleName: string) => string;
15 /** a function that accepts the module name and returns whether it should be included */
16 type AllowlistFunctionType = (moduleName: string) => boolean;
17 interface ModulesFromFileType {
18 exclude?: string | string[] | undefined;
19 include?: string | string[] | undefined;
20 }
21
22 interface Options {
23 /**
24 * An array for the externals to allow, so they will be included in the bundle.
25 * Can accept exact strings ('module_name'), regex patterns (/^module_name/), or a
26 * function that accepts the module name and returns whether it should be included.
27 * Important - if you have set aliases in your webpack config with the exact
28 * same names as modules in node_modules, you need to allowlist them so Webpack will know
29 * they should be bundled.
30 * @default []
31 */
32 allowlist?: AllowlistOption[] | AllowlistOption | undefined;
33 /**
34 * @default ['.bin']
35 */
36 binaryDirs?: string[] | undefined;
37 /**
38 * The method in which unbundled modules will be required in the code. Best to leave as
39 * 'commonjs' for node modules.
40 * @default 'commonjs'
41 */
42 importType?: "var" | "this" | "commonjs" | "amd" | "umd" | "module" | ImportTypeCallback | undefined;
43 /**
44 * The folder in which to search for the node modules.
45 * @default 'node_modules'
46 */
47 modulesDir?: string | undefined;
48 /**
49 * Additional folders to look for node modules.
50 */
51 additionalModuleDirs?: string[] | undefined;
52 /**
53 * Read the modules from the package.json file instead of the node_modules folder.
54 * @default false
55 */
56 modulesFromFile?: boolean | ModulesFromFileType | undefined;
57 /**
58 * @default false
59 */
60 includeAbsolutePaths?: boolean | undefined;
61 }
62}