@@ -17,9 +17,10 @@ type Options = {
1717 jsName : string
1818 outputFile : string
1919 globals : Record < string , string >
20+ forceDevEnv : boolean
2021}
2122
22- const umdDevPlugin = ( type : 'development' | 'production' ) =>
23+ const forceEnvPlugin = ( type : 'development' | 'production' ) =>
2324 replace ( {
2425 'process.env.NODE_ENV' : `"${ type } "` ,
2526 delimiters : [ '' , '' ] ,
@@ -109,15 +110,20 @@ export default function rollup(options: RollupOptions): RollupOptions[] {
109110 ] ,
110111 } ) ,
111112 ...buildConfigs ( {
112- name : 'react-query-devtools-noop ' ,
113+ name : 'react-query-devtools-prod ' ,
113114 packageDir : 'packages/react-query-devtools' ,
114115 jsName : 'ReactQueryDevtools' ,
115- outputFile : 'noop ' ,
116- entryFile : 'src/noop .ts' ,
116+ outputFile : 'index.prod ' ,
117+ entryFile : 'src/index .ts' ,
117118 globals : {
118119 react : 'React' ,
120+ 'react-dom' : 'ReactDOM' ,
119121 '@tanstack/react-query' : 'ReactQuery' ,
122+ '@tanstack/match-sorter-utils' : 'MatchSorterUtils' ,
123+ 'use-sync-external-store/shim/index.js' : 'UseSyncExternalStore' ,
120124 } ,
125+ forceDevEnv : true ,
126+ skipUmdBuild : true ,
121127 } ) ,
122128 ...buildConfigs ( {
123129 name : 'react-query-persist-client' ,
@@ -143,6 +149,9 @@ function buildConfigs(opts: {
143149 globals : Record < string , string >
144150 // This option allows to bundle specified dependencies for umd build
145151 bundleUMDGlobals ?: string [ ]
152+ // Force prod env build
153+ forceDevEnv ?: boolean
154+ skipUmdBuild ?: boolean
146155} ) : RollupOptions [ ] {
147156 const input = path . resolve ( opts . packageDir , opts . entryFile )
148157 const externalDeps = Object . keys ( opts . globals )
@@ -163,46 +172,65 @@ function buildConfigs(opts: {
163172 external,
164173 banner,
165174 globals : opts . globals ,
175+ forceDevEnv : opts . forceDevEnv || false ,
166176 }
167177
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
174188}
175189
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 {
177198 return {
178199 // ESM
179200 external,
180201 input,
181202 output : {
182203 format : 'esm' ,
183- entryFileNames : '[name] .mjs' ,
204+ file : ` ${ packageDir } /build/lib/ ${ outputFile } .mjs` ,
184205 sourcemap : true ,
185- dir : `${ packageDir } /build/lib` ,
186206 banner,
187207 } ,
188208 plugins : [
189209 svelte ( ) ,
190210 babelPlugin ,
191211 commonJS ( ) ,
192212 nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
213+ forceDevEnv ? forceEnvPlugin ( 'development' ) : undefined ,
193214 ] ,
194215 }
195216}
196217
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 {
198226 return {
199227 // CJS
200228 external,
201229 input,
202230 output : {
203231 format : 'cjs' ,
232+ file : `${ packageDir } /build/lib/${ outputFile } .js` ,
204233 sourcemap : true ,
205- dir : `${ packageDir } /build/lib` ,
206234 exports : 'named' ,
207235 banner,
208236 } ,
@@ -211,6 +239,7 @@ function cjs({ input, external, packageDir, banner }: Options): RollupOptions {
211239 babelPlugin ,
212240 commonJS ( ) ,
213241 nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
242+ forceDevEnv ? forceEnvPlugin ( 'development' ) : undefined ,
214243 ] ,
215244 }
216245}
@@ -241,7 +270,7 @@ function umdDev({
241270 babelPlugin ,
242271 nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
243272 commonJS ( ) ,
244- umdDevPlugin ( 'development' ) ,
273+ forceEnvPlugin ( 'development' ) ,
245274 ] ,
246275 }
247276}
@@ -272,7 +301,7 @@ function umdProd({
272301 babelPlugin ,
273302 commonJS ( ) ,
274303 nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
275- umdDevPlugin ( 'production' ) ,
304+ forceEnvPlugin ( 'production' ) ,
276305 terser ( {
277306 mangle : true ,
278307 compress : true ,
0 commit comments