-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: umd build size, force prod devtools #4074
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,37 +14,32 @@ | |
"main": "build/lib/index.js", | ||
"exports": { | ||
".": { | ||
"development": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generated files |
||
"types": "./build/lib/index.d.ts", | ||
"import": "./build/lib/index.mjs", | ||
"default": "./build/lib/index.js" | ||
}, | ||
"default": { | ||
"types": "./build/lib/index.d.ts", | ||
"import": "./build/lib/noop.mjs", | ||
"default": "./cjs.fallback.js" | ||
} | ||
}, | ||
"./production": { | ||
"types": "./build/lib/index.d.ts", | ||
"import": "./build/lib/index.mjs", | ||
"default": "./build/lib/index.js" | ||
}, | ||
"./build/lib/index.prod.js": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This export is needed for modern bundlers to force prod devtools. |
||
"types": "./build/lib/index.d.ts", | ||
"import": "./build/lib/index.prod.mjs", | ||
"default": "./build/lib/index.prod.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"sideEffects": false, | ||
"files": [ | ||
"build/lib/*", | ||
"build/umd/*", | ||
"cjs.fallback.js", | ||
"src" | ||
], | ||
"scripts": { | ||
"clean": "rm -rf ./build", | ||
"test:eslint": "../../node_modules/.bin/eslint --ext .ts,.tsx ./src" | ||
}, | ||
"devDependencies": { | ||
"@types/use-sync-external-store": "^0.0.3" | ||
}, | ||
"dependencies": { | ||
"@tanstack/match-sorter-utils": "^8.1.1", | ||
"@types/use-sync-external-store": "^0.0.3", | ||
"use-sync-external-store": "^1.2.0" | ||
}, | ||
"peerDependencies": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,10 @@ type Options = { | |
jsName: string | ||
outputFile: string | ||
globals: Record<string, string> | ||
forceDevEnv: boolean | ||
} | ||
|
||
const umdDevPlugin = (type: 'development' | 'production') => | ||
const forceEnvPlugin = (type: 'development' | 'production') => | ||
replace({ | ||
'process.env.NODE_ENV': `"${type}"`, | ||
delimiters: ['', ''], | ||
|
@@ -83,8 +84,12 @@ export default function rollup(options: RollupOptions): RollupOptions[] { | |
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
'@tanstack/query-core': 'QueryCore', | ||
'use-sync-external-store/shim/index.js': 'UseSyncExternalStore', | ||
}, | ||
bundleUMDGlobals: ['@tanstack/query-core'], | ||
bundleUMDGlobals: [ | ||
'@tanstack/query-core', | ||
'use-sync-external-store/shim/index.js', | ||
], | ||
}), | ||
...buildConfigs({ | ||
name: 'react-query-devtools', | ||
|
@@ -94,19 +99,31 @@ export default function rollup(options: RollupOptions): RollupOptions[] { | |
entryFile: 'src/index.ts', | ||
globals: { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
'@tanstack/react-query': 'ReactQuery', | ||
'@tanstack/match-sorter-utils': 'MatchSorterUtils', | ||
'use-sync-external-store/shim/index.js': 'UseSyncExternalStore', | ||
}, | ||
bundleUMDGlobals: [ | ||
'@tanstack/match-sorter-utils', | ||
'use-sync-external-store/shim/index.js', | ||
], | ||
}), | ||
...buildConfigs({ | ||
name: 'react-query-devtools-noop', | ||
name: 'react-query-devtools-prod', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This config was changed to contain non-treeshakable devtools build accessible via |
||
packageDir: 'packages/react-query-devtools', | ||
jsName: 'ReactQueryDevtools', | ||
outputFile: 'noop', | ||
entryFile: 'src/noop.ts', | ||
outputFile: 'index.prod', | ||
entryFile: 'src/index.ts', | ||
globals: { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
'@tanstack/react-query': 'ReactQuery', | ||
'@tanstack/match-sorter-utils': 'MatchSorterUtils', | ||
'use-sync-external-store/shim/index.js': 'UseSyncExternalStore', | ||
}, | ||
forceDevEnv: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This forces the build to thinks it's bundling for dev env |
||
skipUmdBuild: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do not want to generate extra set for |
||
}), | ||
...buildConfigs({ | ||
name: 'react-query-persist-client', | ||
|
@@ -132,6 +149,9 @@ function buildConfigs(opts: { | |
globals: Record<string, string> | ||
// This option allows to bundle specified dependencies for umd build | ||
bundleUMDGlobals?: string[] | ||
// Force prod env build | ||
forceDevEnv?: boolean | ||
skipUmdBuild?: boolean | ||
}): RollupOptions[] { | ||
const input = path.resolve(opts.packageDir, opts.entryFile) | ||
const externalDeps = Object.keys(opts.globals) | ||
|
@@ -152,41 +172,65 @@ function buildConfigs(opts: { | |
external, | ||
banner, | ||
globals: opts.globals, | ||
forceDevEnv: opts.forceDevEnv || false, | ||
} | ||
|
||
return [esm(options), cjs(options), umdDev({...options, external: umdExternal}), umdProd({...options, external: umdExternal})] | ||
let builds = [esm(options), cjs(options)] | ||
|
||
if (!opts.skipUmdBuild) { | ||
builds = builds.concat([ | ||
umdDev({ ...options, external: umdExternal }), | ||
umdProd({ ...options, external: umdExternal }), | ||
]) | ||
} | ||
|
||
return builds | ||
} | ||
|
||
function esm({ input, packageDir, external, banner }: Options): RollupOptions { | ||
function esm({ | ||
input, | ||
packageDir, | ||
external, | ||
banner, | ||
outputFile, | ||
forceDevEnv, | ||
}: Options): RollupOptions { | ||
return { | ||
// ESM | ||
external, | ||
input, | ||
output: { | ||
format: 'esm', | ||
entryFileNames: '[name].mjs', | ||
file: `${packageDir}/build/lib/${outputFile}.mjs`, | ||
sourcemap: true, | ||
dir: `${packageDir}/build/lib`, | ||
banner, | ||
}, | ||
plugins: [ | ||
svelte(), | ||
babelPlugin, | ||
commonJS(), | ||
nodeResolve({ extensions: ['.ts', '.tsx'] }), | ||
forceDevEnv ? forceEnvPlugin('development') : undefined, | ||
], | ||
} | ||
} | ||
|
||
function cjs({ input, external, packageDir, banner }: Options): RollupOptions { | ||
function cjs({ | ||
input, | ||
external, | ||
packageDir, | ||
banner, | ||
outputFile, | ||
forceDevEnv, | ||
}: Options): RollupOptions { | ||
return { | ||
// CJS | ||
external, | ||
input, | ||
output: { | ||
format: 'cjs', | ||
file: `${packageDir}/build/lib/${outputFile}.js`, | ||
sourcemap: true, | ||
dir: `${packageDir}/build/lib`, | ||
exports: 'named', | ||
banner, | ||
}, | ||
|
@@ -195,6 +239,7 @@ function cjs({ input, external, packageDir, banner }: Options): RollupOptions { | |
babelPlugin, | ||
commonJS(), | ||
nodeResolve({ extensions: ['.ts', '.tsx'] }), | ||
forceDevEnv ? forceEnvPlugin('development') : undefined, | ||
], | ||
} | ||
} | ||
|
@@ -225,7 +270,7 @@ function umdDev({ | |
babelPlugin, | ||
nodeResolve({ extensions: ['.ts', '.tsx'] }), | ||
commonJS(), | ||
umdDevPlugin('development'), | ||
forceEnvPlugin('development'), | ||
], | ||
} | ||
} | ||
|
@@ -256,7 +301,7 @@ function umdProd({ | |
babelPlugin, | ||
commonJS(), | ||
nodeResolve({ extensions: ['.ts', '.tsx'] }), | ||
umdDevPlugin('production'), | ||
forceEnvPlugin('production'), | ||
terser({ | ||
mangle: true, | ||
compress: true, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed due to a bug in typescript which supposed to support
exports
, but actually does not map to a proper file.