Skip to content

Commit 5dd97e4

Browse files
committed
add base rollup config for node bundles
1 parent 816941e commit 5dd97e4

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

rollup/bundleHelpers.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
* Rollup config docs: https://rollupjs.org/guide/en/#big-list-of-options
33
*/
44

5+
import { builtinModules } from 'module';
6+
57
import deepMerge from 'deepmerge';
68

79
import {
810
makeBrowserBuildPlugin,
11+
makeCommonJSPlugin,
912
makeIsDebugBuildPlugin,
1013
makeLicensePlugin,
1114
makeNodeResolvePlugin,
@@ -28,13 +31,19 @@ export function makeBaseBundleConfig(options) {
2831
const licensePlugin = makeLicensePlugin(licenseTitle);
2932
const tsPlugin = makeTSPlugin(jsVersion.toLowerCase());
3033

34+
// The `commonjs` plugin is the `esModuleInterop` of the bundling world. When used with `transformMixedEsModules`, it
35+
// will include all dependencies, imported or required, in the final bundle. (Without it, CJS modules aren't included
36+
// at all, and without `transformMixedEsModules`, they're only included if they're imported, not if they're required.)
37+
const commonJSPlugin = makeCommonJSPlugin({ transformMixedEsModules: true });
38+
3139
// used by `@sentry/browser`, `@sentry/tracing`, and `@sentry/vue` (bundles which are a full SDK in and of themselves)
3240
const standAloneBundleConfig = {
3341
output: {
3442
format: 'iife',
3543
name: 'Sentry',
3644
},
3745
context: 'window',
46+
plugins: [markAsBrowserBuildPlugin],
3847
};
3948

4049
// used by `@sentry/integrations` and `@sentry/wasm` (bundles which need to be combined with a stand-alone SDK bundle)
@@ -67,6 +76,17 @@ export function makeBaseBundleConfig(options) {
6776
// code to add after the CJS wrapper
6877
footer: '}(window));',
6978
},
79+
plugins: [markAsBrowserBuildPlugin],
80+
};
81+
82+
// used by `@sentry/serverless`, when creating the lambda layer
83+
const nodeBundleConfig = {
84+
output: {
85+
format: 'cjs',
86+
},
87+
plugins: [commonJSPlugin],
88+
// Don't bundle any of Node's core modules
89+
external: builtinModules,
7090
};
7191

7292
// used by all bundles
@@ -81,21 +101,15 @@ export function makeBaseBundleConfig(options) {
81101
},
82102
plugins:
83103
jsVersion === 'es5'
84-
? [tsPlugin, markAsBrowserBuildPlugin, nodeResolvePlugin, licensePlugin]
85-
: [
86-
sucrasePlugin,
87-
removeBlankLinesPlugin,
88-
removeESLintCommentsPlugin,
89-
markAsBrowserBuildPlugin,
90-
nodeResolvePlugin,
91-
licensePlugin,
92-
],
104+
? [tsPlugin, nodeResolvePlugin, licensePlugin]
105+
: [sucrasePlugin, removeBlankLinesPlugin, removeESLintCommentsPlugin, nodeResolvePlugin, licensePlugin],
93106
treeshake: 'smallest',
94107
};
95108

96109
const bundleTypeConfigMap = {
97110
standalone: standAloneBundleConfig,
98111
addon: addOnBundleConfig,
112+
node: nodeBundleConfig,
99113
};
100114

101115
return deepMerge(sharedBundleConfig, bundleTypeConfigMap[bundleType], {

0 commit comments

Comments
 (0)