@@ -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 : [ '' , '' ] ,
@@ -83,8 +84,12 @@ export default function rollup(options: RollupOptions): RollupOptions[] {
8384 react : 'React' ,
8485 'react-dom' : 'ReactDOM' ,
8586 '@tanstack/query-core' : 'QueryCore' ,
87+ 'use-sync-external-store/shim/index.js' : 'UseSyncExternalStore' ,
8688 } ,
87- bundleUMDGlobals : [ '@tanstack/query-core' ] ,
89+ bundleUMDGlobals : [
90+ '@tanstack/query-core' ,
91+ 'use-sync-external-store/shim/index.js' ,
92+ ] ,
8893 } ) ,
8994 ...buildConfigs ( {
9095 name : 'react-query-devtools' ,
@@ -94,19 +99,31 @@ export default function rollup(options: RollupOptions): RollupOptions[] {
9499 entryFile : 'src/index.ts' ,
95100 globals : {
96101 react : 'React' ,
102+ 'react-dom' : 'ReactDOM' ,
97103 '@tanstack/react-query' : 'ReactQuery' ,
104+ '@tanstack/match-sorter-utils' : 'MatchSorterUtils' ,
105+ 'use-sync-external-store/shim/index.js' : 'UseSyncExternalStore' ,
98106 } ,
107+ bundleUMDGlobals : [
108+ '@tanstack/match-sorter-utils' ,
109+ 'use-sync-external-store/shim/index.js' ,
110+ ] ,
99111 } ) ,
100112 ...buildConfigs ( {
101- name : 'react-query-devtools-noop ' ,
113+ name : 'react-query-devtools-prod ' ,
102114 packageDir : 'packages/react-query-devtools' ,
103115 jsName : 'ReactQueryDevtools' ,
104- outputFile : 'noop ' ,
105- entryFile : 'src/noop .ts' ,
116+ outputFile : 'index.prod ' ,
117+ entryFile : 'src/index .ts' ,
106118 globals : {
107119 react : 'React' ,
120+ 'react-dom' : 'ReactDOM' ,
108121 '@tanstack/react-query' : 'ReactQuery' ,
122+ '@tanstack/match-sorter-utils' : 'MatchSorterUtils' ,
123+ 'use-sync-external-store/shim/index.js' : 'UseSyncExternalStore' ,
109124 } ,
125+ forceDevEnv : true ,
126+ skipUmdBuild : true ,
110127 } ) ,
111128 ...buildConfigs ( {
112129 name : 'react-query-persist-client' ,
@@ -132,6 +149,9 @@ function buildConfigs(opts: {
132149 globals : Record < string , string >
133150 // This option allows to bundle specified dependencies for umd build
134151 bundleUMDGlobals ?: string [ ]
152+ // Force prod env build
153+ forceDevEnv ?: boolean
154+ skipUmdBuild ?: boolean
135155} ) : RollupOptions [ ] {
136156 const input = path . resolve ( opts . packageDir , opts . entryFile )
137157 const externalDeps = Object . keys ( opts . globals )
@@ -152,41 +172,65 @@ function buildConfigs(opts: {
152172 external,
153173 banner,
154174 globals : opts . globals ,
175+ forceDevEnv : opts . forceDevEnv || false ,
155176 }
156177
157- return [ esm ( options ) , cjs ( options ) , umdDev ( { ...options , external : umdExternal } ) , umdProd ( { ...options , external : umdExternal } ) ]
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
158188}
159189
160- 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 {
161198 return {
162199 // ESM
163200 external,
164201 input,
165202 output : {
166203 format : 'esm' ,
167- entryFileNames : '[name] .mjs' ,
204+ file : ` ${ packageDir } /build/lib/ ${ outputFile } .mjs` ,
168205 sourcemap : true ,
169- dir : `${ packageDir } /build/lib` ,
170206 banner,
171207 } ,
172208 plugins : [
173209 svelte ( ) ,
174210 babelPlugin ,
175211 commonJS ( ) ,
176212 nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
213+ forceDevEnv ? forceEnvPlugin ( 'development' ) : undefined ,
177214 ] ,
178215 }
179216}
180217
181- 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 {
182226 return {
183227 // CJS
184228 external,
185229 input,
186230 output : {
187231 format : 'cjs' ,
232+ file : `${ packageDir } /build/lib/${ outputFile } .js` ,
188233 sourcemap : true ,
189- dir : `${ packageDir } /build/lib` ,
190234 exports : 'named' ,
191235 banner,
192236 } ,
@@ -195,6 +239,7 @@ function cjs({ input, external, packageDir, banner }: Options): RollupOptions {
195239 babelPlugin ,
196240 commonJS ( ) ,
197241 nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
242+ forceDevEnv ? forceEnvPlugin ( 'development' ) : undefined ,
198243 ] ,
199244 }
200245}
@@ -225,7 +270,7 @@ function umdDev({
225270 babelPlugin ,
226271 nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
227272 commonJS ( ) ,
228- umdDevPlugin ( 'development' ) ,
273+ forceEnvPlugin ( 'development' ) ,
229274 ] ,
230275 }
231276}
@@ -256,7 +301,7 @@ function umdProd({
256301 babelPlugin ,
257302 commonJS ( ) ,
258303 nodeResolve ( { extensions : [ '.ts' , '.tsx' ] } ) ,
259- umdDevPlugin ( 'production' ) ,
304+ forceEnvPlugin ( 'production' ) ,
260305 terser ( {
261306 mangle : true ,
262307 compress : true ,
0 commit comments