Skip to content

Commit d3fcd0b

Browse files
authored
Merge pull request #1565 from nickgros/SWC-7242
SWC-7242
2 parents ed11a14 + 229a580 commit d3fcd0b

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

packages/synapse-react-client/vite.config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ import { ConfigBuilder } from 'vite-config'
66
*/
77
const config = new ConfigBuilder()
88
.setIncludeReactConfig(true)
9-
.setIncludeLibraryConfig(true)
10-
.setBuildLibEntry(resolve(__dirname, 'src/index.ts'))
9+
.setIncludeLibraryConfig(true, {
10+
except: [
11+
// Include @sage-bionetworks/synapse-types because the local version may drift from the version released on NPM
12+
'@sage-bionetworks/synapse-types',
13+
],
14+
})
15+
.setBuildLibEntry(resolve(__dirname, 'src/umd.index.ts'))
1116
.setConfigOverrides({
1217
root: '.',
1318
build: {

packages/vite-config/src/ConfigBuilder.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import viteLibraryConfig from './vite-library-config.js'
55
import vitestConfig from './vitest-config.js'
66

77
export class ConfigBuilder {
8-
private includeReactConfig = false
98
private includeLibraryConfig = false
109
private buildLibEntry: string | string[] | undefined = undefined
1110
private includeVitestConfig = false
1211
private pluginConfigOptions: PluginConfigOptions = {}
1312
private configOverrides: Record<string, any> | null = null
1413

1514
setIncludeReactConfig(includeReactConfig: boolean): ConfigBuilder {
16-
this.includeReactConfig = includeReactConfig
15+
this.pluginConfigOptions.includeReactPlugins = includeReactConfig
1716
return this
1817
}
1918

@@ -27,15 +26,14 @@ export class ConfigBuilder {
2726
return this
2827
}
2928

30-
setIncludeLibraryConfig(includeLibraryConfig: boolean): ConfigBuilder {
31-
this.includeLibraryConfig = includeLibraryConfig
32-
return this
33-
}
34-
35-
setPluginConfigOptions(
36-
pluginConfigOptions: PluginConfigOptions,
29+
setIncludeLibraryConfig(
30+
includeLibraryConfig: boolean,
31+
externalizeDepsOptions?: Parameters<
32+
typeof getPluginConfig
33+
>[0]['externalizeDepsOptions'],
3734
): ConfigBuilder {
38-
this.pluginConfigOptions = pluginConfigOptions
35+
this.includeLibraryConfig = includeLibraryConfig
36+
this.pluginConfigOptions.externalizeDepsOptions = externalizeDepsOptions
3937
return this
4038
}
4139

@@ -63,7 +61,7 @@ export class ConfigBuilder {
6361
if (this.pluginConfigOptions) {
6462
config = mergeConfig(config, {
6563
plugins: getPluginConfig({
66-
includeReactPlugins: this.includeReactConfig,
64+
...this.pluginConfigOptions,
6765
includeLibraryPlugins: this.includeLibraryConfig,
6866
}),
6967
})

packages/vite-config/src/pluginConfig.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import dts from 'vite-plugin-dts'
88
export type PluginConfigOptions = {
99
includeReactPlugins?: boolean
1010
includeLibraryPlugins?: boolean
11+
externalizeDepsOptions?: Parameters<typeof externalizeDeps>[0]
1112
}
1213

1314
/**
@@ -34,14 +35,18 @@ const REACT_PLUGINS: PluginOption[] = [
3435
/**
3536
* Plugins that libraries that should emit ESM and CJS bundles will use
3637
*/
37-
const LIBRARY_PLUGINS: PluginOption[] = [
38-
// Do not bundle any dependencies; the consumer's bundler will resolve and link them.
39-
externalizeDeps(),
40-
// Generate a single type definition file for distribution.
41-
dts({
42-
rollupTypes: true,
43-
}),
44-
]
38+
function getLibraryPlugins(
39+
externalizeDepsOptions?: Parameters<typeof externalizeDeps>[0],
40+
): PluginOption[] {
41+
return [
42+
// Do not bundle any dependencies; the consumer's bundler will resolve and link them.
43+
externalizeDeps(externalizeDepsOptions),
44+
// Generate a single type definition file for distribution.
45+
dts({
46+
rollupTypes: true,
47+
}),
48+
]
49+
}
4550

4651
/**
4752
* Get a shared configuration of Vite plugins to use based on the provided options. Note that Vite does not deeply merge
@@ -53,7 +58,7 @@ export function getPluginConfig(options: PluginConfigOptions): PluginOption[] {
5358
plugins.push(...REACT_PLUGINS)
5459
}
5560
if (options.includeLibraryPlugins) {
56-
plugins.push(...LIBRARY_PLUGINS)
61+
plugins.push(...getLibraryPlugins(options.externalizeDepsOptions))
5762
}
5863
return plugins
5964
}

0 commit comments

Comments
 (0)