Skip to content

Commit 7c71013

Browse files
authored
feat(build): Allow for multiple bundle entrypoints (#5143)
This adds the ability to create more than one bundle with a single bundle rollup config, by specifying multiple entrypoints. Because multiple files can now be output, the way they're named also needed to be switched, from providing a static string to providing a function to determine the name of each bundle. Finally, the name of the option (`input`) was changed to match the corresponding option used in the building of npm packages (`entryponts`).
1 parent 263257f commit 7c71013

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

packages/browser/rollup.bundle.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const builds = [];
55
['es5', 'es6'].forEach(jsVersion => {
66
const baseBundleConfig = makeBaseBundleConfig({
77
bundleType: 'standalone',
8-
input: 'src/index.ts',
8+
entrypoints: ['src/index.ts'],
99
jsVersion,
1010
licenseTitle: '@sentry/browser',
11-
outputFileBase: `bundles/bundle${jsVersion === 'es5' ? '.es5' : ''}`,
11+
outputFileBase: () => `bundles/bundle${jsVersion === 'es5' ? '.es5' : ''}`,
1212
});
1313

1414
builds.push(...makeBundleConfigVariants(baseBundleConfig));

packages/integrations/rollup.bundle.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ const jsVersion = process.env.JS_VERSION;
99

1010
const baseBundleConfig = makeBaseBundleConfig({
1111
bundleType: 'addon',
12-
input: `src/${file}`,
12+
entrypoints: [`src/${file}`],
1313
jsVersion,
1414
licenseTitle: '@sentry/integrations',
15-
outputFileBase: `bundles/${file.replace('.ts', '')}${jsVersion === 'ES5' ? '.es5' : ''}`,
15+
outputFileBase: ({ name: entrypoint }) => `bundles/${entrypoint}${jsVersion === 'ES5' ? '.es5' : ''}`,
1616
});
1717

1818
// TODO We only need `commonjs` for localforage (used in the offline plugin). Once that's fixed, this can come out.

packages/tracing/rollup.bundle.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const builds = [];
55
['es5', 'es6'].forEach(jsVersion => {
66
const baseBundleConfig = makeBaseBundleConfig({
77
bundleType: 'standalone',
8-
input: 'src/index.bundle.ts',
8+
entrypoints: ['src/index.bundle.ts'],
99
jsVersion,
1010
licenseTitle: '@sentry/tracing & @sentry/browser',
11-
outputFileBase: `bundles/bundle.tracing${jsVersion === 'es5' ? '.es5' : ''}`,
11+
outputFileBase: () => `bundles/bundle.tracing${jsVersion === 'es5' ? '.es5' : ''}`,
1212
});
1313

1414
builds.push(...makeBundleConfigVariants(baseBundleConfig));

packages/vue/rollup.bundle.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/ind
22

33
const baseBundleConfig = makeBaseBundleConfig({
44
bundleType: 'standalone',
5-
input: 'src/index.bundle.ts',
5+
entrypoints: ['src/index.bundle.ts'],
66
jsVersion: 'es6',
77
licenseTitle: '@sentry/vue',
8-
outputFileBase: 'bundle.vue',
8+
outputFileBase: () => 'bundle.vue',
99
});
1010

1111
export default makeBundleConfigVariants(baseBundleConfig);

packages/wasm/rollup.bundle.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/ind
22

33
const baseBundleConfig = makeBaseBundleConfig({
44
bundleType: 'addon',
5-
input: 'src/index.ts',
5+
entrypoints: ['src/index.ts'],
66
jsVersion: 'es6',
77
licenseTitle: '@sentry/wasm',
8-
outputFileBase: 'bundles/wasm',
8+
outputFileBase: () => 'bundles/wasm',
99
});
1010

1111
export default makeBundleConfigVariants(baseBundleConfig);

rollup/bundleHelpers.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import { mergePlugins } from './utils';
2222

2323
export function makeBaseBundleConfig(options) {
24-
const { bundleType, input, jsVersion, licenseTitle, outputFileBase } = options;
24+
const { bundleType, entrypoints, jsVersion, licenseTitle, outputFileBase } = options;
2525

2626
const nodeResolvePlugin = makeNodeResolvePlugin();
2727
const sucrasePlugin = makeSucrasePlugin();
@@ -91,10 +91,11 @@ export function makeBaseBundleConfig(options) {
9191

9292
// used by all bundles
9393
const sharedBundleConfig = {
94-
input,
94+
input: entrypoints,
9595
output: {
9696
// a file extension will be added to this base value when we specify either a minified or non-minified build
97-
file: `build/${outputFileBase}`,
97+
entryFileNames: outputFileBase,
98+
dir: 'build',
9899
sourcemap: true,
99100
strict: false,
100101
esModule: false,
@@ -136,7 +137,7 @@ export function makeBundleConfigVariants(baseConfig) {
136137
const variantSpecificConfigs = [
137138
{
138139
output: {
139-
file: `${baseConfig.output.file}.js`,
140+
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.js`,
140141
},
141142
plugins: [includeDebuggingPlugin],
142143
},
@@ -150,13 +151,13 @@ export function makeBundleConfigVariants(baseConfig) {
150151
// },
151152
{
152153
output: {
153-
file: `${baseConfig.output.file}.min.js`,
154+
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.min.js`,
154155
},
155156
plugins: [stripDebuggingPlugin, terserPlugin],
156157
},
157158
{
158159
output: {
159-
file: `${baseConfig.output.file}.debug.min.js`,
160+
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.debug.min.js`,
160161
},
161162
plugins: [terserPlugin],
162163
},

0 commit comments

Comments
 (0)