Skip to content

Commit c4728ab

Browse files
committed
fix: devtools force production
1 parent 37a786b commit c4728ab

File tree

4 files changed

+53
-44
lines changed

4 files changed

+53
-44
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"test:jest": "lerna run test:codemods --stream --no-bail && jest --config ./jest.config.ts",
1515
"test:jest:dev": "jest --config ./jest.config.ts --watch",
1616
"test:size": "npm run build && bundlewatch",
17-
"build": "rollup --config rollup.config.js && npm run typecheck",
17+
"build": "rollup --config rollup.config.js && npm run typecheck && npm run build:copyTypes",
18+
"build:copyTypes": "cp packages/react-query-devtools/build/lib/index.d.ts packages/react-query-devtools/build/lib/index.prod.d.ts",
1819
"typecheck": "tsc -b",
1920
"watch": "concurrently --kill-others \"rollup --config rollup.config.js -w\" \"npm run typecheck -- --watch\" \"npm run test\"",
2021
"linkAll": "lerna exec 'npm run link' --parallel",

packages/react-query-devtools/cjs.fallback.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/react-query-devtools/package.json

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,20 @@
1414
"main": "build/lib/index.js",
1515
"exports": {
1616
".": {
17-
"development": {
18-
"types": "./build/lib/index.d.ts",
19-
"import": "./build/lib/index.mjs",
20-
"default": "./build/lib/index.js"
21-
},
22-
"default": {
23-
"types": "./build/lib/index.d.ts",
24-
"import": "./build/lib/noop.mjs",
25-
"default": "./cjs.fallback.js"
26-
}
27-
},
28-
"./production": {
2917
"types": "./build/lib/index.d.ts",
3018
"import": "./build/lib/index.mjs",
3119
"default": "./build/lib/index.js"
3220
},
21+
"./build/lib/index.prod.js": {
22+
"types": "./build/lib/index.d.ts",
23+
"import": "./build/lib/index.prod.mjs",
24+
"default": "./build/lib/index.prod.js"
25+
},
3326
"./package.json": "./package.json"
3427
},
3528
"files": [
3629
"build/lib/*",
3730
"build/umd/*",
38-
"cjs.fallback.js",
3931
"src"
4032
],
4133
"scripts": {

rollup.config.ts

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)