@@ -17,9 +17,10 @@ type Options = {
17
17
jsName : string
18
18
outputFile : string
19
19
globals : Record < string , string >
20
+ forceDevEnv : boolean
20
21
}
21
22
22
- const umdDevPlugin = ( type : 'development' | 'production' ) =>
23
+ const forceEnvPlugin = ( type : 'development' | 'production' ) =>
23
24
replace ( {
24
25
'process.env.NODE_ENV' : `"${ type } "` ,
25
26
delimiters : [ '' , '' ] ,
@@ -109,15 +110,20 @@ export default function rollup(options: RollupOptions): RollupOptions[] {
109
110
] ,
110
111
} ) ,
111
112
...buildConfigs ( {
112
- name : 'react-query-devtools-noop ' ,
113
+ name : 'react-query-devtools-prod ' ,
113
114
packageDir : 'packages/react-query-devtools' ,
114
115
jsName : 'ReactQueryDevtools' ,
115
- outputFile : 'noop ' ,
116
- entryFile : 'src/noop .ts' ,
116
+ outputFile : 'index.prod ' ,
117
+ entryFile : 'src/index .ts' ,
117
118
globals : {
118
119
react : 'React' ,
120
+ 'react-dom' : 'ReactDOM' ,
119
121
'@tanstack/react-query' : 'ReactQuery' ,
122
+ '@tanstack/match-sorter-utils' : 'MatchSorterUtils' ,
123
+ 'use-sync-external-store/shim/index.js' : 'UseSyncExternalStore' ,
120
124
} ,
125
+ forceDevEnv : true ,
126
+ skipUmdBuild : true ,
121
127
} ) ,
122
128
...buildConfigs ( {
123
129
name : 'react-query-persist-client' ,
@@ -143,6 +149,9 @@ function buildConfigs(opts: {
143
149
globals : Record < string , string >
144
150
// This option allows to bundle specified dependencies for umd build
145
151
bundleUMDGlobals ?: string [ ]
152
+ // Force prod env build
153
+ forceDevEnv ?: boolean
154
+ skipUmdBuild ?: boolean
146
155
} ) : RollupOptions [ ] {
147
156
const input = path . resolve ( opts . packageDir , opts . entryFile )
148
157
const externalDeps = Object . keys ( opts . globals )
@@ -163,46 +172,65 @@ function buildConfigs(opts: {
163
172
external,
164
173
banner,
165
174
globals : opts . globals ,
175
+ forceDevEnv : opts . forceDevEnv || false ,
166
176
}
167
177
168
- return [
169
- esm ( options ) ,
170
- cjs ( options ) ,
171
- umdDev ( { ...options , external : umdExternal } ) ,
172
- umdProd ( { ...options , external : umdExternal } ) ,
173
- ]
178
+ let builds = [ esm ( options ) , cjs ( options ) ]
179
+
180
+ if ( ! opts . skipUmdBuild ) {
181
+ builds = builds . concat ( [
182
+ umdDev ( { ...options , external : umdExternal } ) ,
183
+ umdProd ( { ...options , external : umdExternal } ) ,
184
+ ] )
185
+ }
186
+
187
+ return builds
174
188
}
175
189
176
- function esm ( { input, packageDir, external, banner } : Options ) : RollupOptions {
190
+ function esm ( {
191
+ input,
192
+ packageDir,
193
+ external,
194
+ banner,
195
+ outputFile,
196
+ forceDevEnv,
197
+ } : Options ) : RollupOptions {
177
198
return {
178
199
// ESM
179
200
external,
180
201
input,
181
202
output : {
182
203
format : 'esm' ,
183
- entryFileNames : '[name] .mjs' ,
204
+ file : ` ${ packageDir } /build/lib/ ${ outputFile } .mjs` ,
184
205
sourcemap : true ,
185
- dir : `${ packageDir } /build/lib` ,
186
206
banner,
187
207
} ,
188
208
plugins : [
189
209
svelte ( ) ,
190
210
babelPlugin ,
191
211
commonJS ( ) ,
192
212
nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
213
+ forceDevEnv ? forceEnvPlugin ( 'development' ) : undefined ,
193
214
] ,
194
215
}
195
216
}
196
217
197
- function cjs ( { input, external, packageDir, banner } : Options ) : RollupOptions {
218
+ function cjs ( {
219
+ input,
220
+ external,
221
+ packageDir,
222
+ banner,
223
+ outputFile,
224
+ forceDevEnv,
225
+ } : Options ) : RollupOptions {
198
226
return {
199
227
// CJS
200
228
external,
201
229
input,
202
230
output : {
203
231
format : 'cjs' ,
232
+ file : `${ packageDir } /build/lib/${ outputFile } .js` ,
204
233
sourcemap : true ,
205
- dir : `${ packageDir } /build/lib` ,
206
234
exports : 'named' ,
207
235
banner,
208
236
} ,
@@ -211,6 +239,7 @@ function cjs({ input, external, packageDir, banner }: Options): RollupOptions {
211
239
babelPlugin ,
212
240
commonJS ( ) ,
213
241
nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
242
+ forceDevEnv ? forceEnvPlugin ( 'development' ) : undefined ,
214
243
] ,
215
244
}
216
245
}
@@ -241,7 +270,7 @@ function umdDev({
241
270
babelPlugin ,
242
271
nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
243
272
commonJS ( ) ,
244
- umdDevPlugin ( 'development' ) ,
273
+ forceEnvPlugin ( 'development' ) ,
245
274
] ,
246
275
}
247
276
}
@@ -272,7 +301,7 @@ function umdProd({
272
301
babelPlugin ,
273
302
commonJS ( ) ,
274
303
nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
275
- umdDevPlugin ( 'production' ) ,
304
+ forceEnvPlugin ( 'production' ) ,
276
305
terser ( {
277
306
mangle : true ,
278
307
compress : true ,
0 commit comments