@@ -7,6 +7,22 @@ interface UserOptions {
7
7
deps : boolean ,
8
8
devDeps : boolean ,
9
9
except : Array < string | RegExp > ,
10
+ /**
11
+ * Additional dependencies to externalize.
12
+ *
13
+ * @example
14
+ *
15
+ * ```ts
16
+ * externalizeDeps({
17
+ * include: [
18
+ * /^unlisted-dep(?:\/.*)?$/,
19
+ * ],
20
+ * })
21
+ * ```
22
+ *
23
+ * @default []
24
+ */
25
+ include : Array < string | RegExp > ,
10
26
nodeBuiltins : boolean ,
11
27
optionalDeps : boolean ,
12
28
peerDeps : boolean ,
@@ -38,6 +54,12 @@ const parseFile = (file: string) => {
38
54
* // Or match patterns with regular expressions.
39
55
* /^@some\/obscure(?:\/.+)?$/,
40
56
* ],
57
+ * include: [
58
+ * // Match exact values with strings.
59
+ * '@some/obscure/dependency',
60
+ * // Or match patterns with regular expressions.
61
+ * /^@some\/obscure(?:\/.+)?$/,
62
+ * ],
41
63
* nodeBuiltins: true,
42
64
* optionalDeps: true,
43
65
* peerDeps: true,
@@ -52,6 +74,7 @@ export const externalizeDeps = (options: Partial<UserOptions> = {}): Plugin => {
52
74
deps : true ,
53
75
devDeps : false ,
54
76
except : [ ] ,
77
+ include : [ ] ,
55
78
nodeBuiltins : true ,
56
79
optionalDeps : true ,
57
80
peerDeps : true ,
@@ -116,6 +139,7 @@ export const externalizeDeps = (options: Partial<UserOptions> = {}): Plugin => {
116
139
}
117
140
118
141
const depMatchers = Array . from ( externalDeps )
142
+
119
143
const isException = ( id : string ) => {
120
144
return optionsResolved . except . some ( ( exception ) => {
121
145
if ( typeof exception === 'string' ) {
@@ -126,6 +150,16 @@ export const externalizeDeps = (options: Partial<UserOptions> = {}): Plugin => {
126
150
} )
127
151
}
128
152
153
+ const isIncluded = ( id : string ) => {
154
+ return optionsResolved . include . some ( ( included ) => {
155
+ if ( typeof included === 'string' ) {
156
+ return included === id
157
+ }
158
+
159
+ return included . test ( id )
160
+ } )
161
+ }
162
+
129
163
return {
130
164
build : {
131
165
rollupOptions : {
@@ -134,6 +168,10 @@ export const externalizeDeps = (options: Partial<UserOptions> = {}): Plugin => {
134
168
return false
135
169
}
136
170
171
+ if ( isIncluded ( id ) ) {
172
+ return true
173
+ }
174
+
137
175
return depMatchers . some ( ( depMatcher ) => depMatcher . test ( id ) )
138
176
} ,
139
177
} ,
0 commit comments