Skip to content

Commit 8feda19

Browse files
authored
Merge pull request #1763 from Antignote/feature/umd_unique_namespace
2 parents 69d6965 + 2bdcd52 commit 8feda19

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/toolkit/scripts/build.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,21 @@ const entryPoints: EntryPointOptions[] = [
9797
folder: '',
9898
entryPoint: 'src/index.ts',
9999
extractionConfig: 'api-extractor.json',
100+
globalName: 'RTK',
100101
},
101102
{
102103
prefix: 'rtk-query',
103104
folder: 'query',
104105
entryPoint: 'src/query/index.ts',
105106
extractionConfig: 'api-extractor.query.json',
107+
globalName: 'RTKQ',
106108
},
107109
{
108110
prefix: 'rtk-query-react',
109111
folder: 'query/react',
110112
entryPoint: 'src/query/react/index.ts',
111113
extractionConfig: 'api-extractor.query-react.json',
114+
globalName: 'RTKQ',
112115
},
113116
]
114117

@@ -250,10 +253,7 @@ async function bundle(options: BuildOptions & EntryPointOptions) {
250253
/**
251254
* since esbuild doesn't support umd, we use rollup to convert esm to umd
252255
*/
253-
async function buildUMD(outputPath: string, prefix: string) {
254-
// All RTK UMD files share the same global variable name, regardless
255-
const globalName = 'RTK'
256-
256+
async function buildUMD(outputPath: string, prefix: string, globalName: string) {
257257
for (let umdExtension of ['umd', 'umd.min']) {
258258
const input = path.join(outputPath, `${prefix}.${umdExtension}.js`)
259259
const instance = await rollup.rollup({
@@ -319,7 +319,7 @@ async function main({ skipExtraction = false, local = false }: BuildArgs) {
319319
for (let entryPoint of entryPoints) {
320320
const { folder } = entryPoint
321321
const outputPath = path.join('dist', folder)
322-
await buildUMD(outputPath, entryPoint.prefix)
322+
await buildUMD(outputPath, entryPoint.prefix, entryPoint.globalName)
323323
}
324324

325325
// We need one additional package.json file in dist to support

packages/toolkit/scripts/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ export interface EntryPointOptions {
1919
folder: string
2020
entryPoint: string
2121
extractionConfig: string
22+
// globalName is used in the conversion to umd files to separate rtk from rtk-query on a global namespace
23+
globalName: string
2224
}

0 commit comments

Comments
 (0)