Skip to content
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 issue where the global RTK object got overwritten in the UMD files #1763

Merged
merged 2 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/toolkit/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,21 @@ const entryPoints: EntryPointOptions[] = [
folder: '',
entryPoint: 'src/index.ts',
extractionConfig: 'api-extractor.json',
globalName: 'RTK',
},
{
prefix: 'rtk-query',
folder: 'query',
entryPoint: 'src/query/index.ts',
extractionConfig: 'api-extractor.query.json',
globalName: 'RTK.QUERY',
Antignote marked this conversation as resolved.
Show resolved Hide resolved
},
{
prefix: 'rtk-query-react',
folder: 'query/react',
entryPoint: 'src/query/react/index.ts',
extractionConfig: 'api-extractor.query-react.json',
globalName: 'RTK.QUERY.REACT',
Antignote marked this conversation as resolved.
Show resolved Hide resolved
},
]

Expand Down Expand Up @@ -250,10 +253,7 @@ async function bundle(options: BuildOptions & EntryPointOptions) {
/**
* since esbuild doesn't support umd, we use rollup to convert esm to umd
*/
async function buildUMD(outputPath: string, prefix: string) {
// All RTK UMD files share the same global variable name, regardless
const globalName = 'RTK'

async function buildUMD(outputPath: string, prefix: string, globalName: string) {
for (let umdExtension of ['umd', 'umd.min']) {
const input = path.join(outputPath, `${prefix}.${umdExtension}.js`)
const instance = await rollup.rollup({
Expand Down Expand Up @@ -319,7 +319,7 @@ async function main({ skipExtraction = false, local = false }: BuildArgs) {
for (let entryPoint of entryPoints) {
const { folder } = entryPoint
const outputPath = path.join('dist', folder)
await buildUMD(outputPath, entryPoint.prefix)
await buildUMD(outputPath, entryPoint.prefix, entryPoint.globalName)
}

// We need one additional package.json file in dist to support
Expand Down
2 changes: 2 additions & 0 deletions packages/toolkit/scripts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ export interface EntryPointOptions {
folder: string
entryPoint: string
extractionConfig: string
// globalName is used in the conversion to umd files to separate rtk from rtk-query on a global name space
globalName: string
}