11/**
2- * Rollup config docs: https://rollupjs.org/guide/en/#big-list-of -options
2+ * Rolldown config docs: https://rolldown.rs/reference/config -options
33 */
44
5- import { builtinModules } from 'module' ;
5+ import * as fs from 'fs' ;
6+ import * as path from 'path' ;
67
78import deepMerge from 'deepmerge' ;
89
910import {
11+ makeBannerOptions ,
1012 makeBrowserBuildPlugin ,
11- makeCommonJSPlugin ,
12- makeEsbuildPlugin ,
1313 makeIsDebugBuildPlugin ,
14- makeLicensePlugin ,
15- makeNodeResolvePlugin ,
14+ makeMinifierOptions ,
1615 makeRrwebBuildPlugin ,
1716 makeSetSDKSourcePlugin ,
18- makeTerserPlugin ,
1917} from './plugins/index.mjs' ;
20- import { mergePlugins } from './utils.mjs' ;
18+ import { getNodeBuiltIns , mergePlugins , treeShakePreset } from './utils.mjs' ;
2119import { makeProductionReplacePlugin } from './plugins/npmPlugins.mjs' ;
2220
2321const BUNDLE_VARIANTS = [ '.js' , '.min.js' , '.debug.min.js' ] ;
2422
23+ const packageDotJSON = JSON . parse ( fs . readFileSync ( path . resolve ( process . cwd ( ) , './package.json' ) , { encoding : 'utf8' } ) ) ;
24+
2525export function makeBaseBundleConfig ( options ) {
26- const { bundleType, entrypoints, licenseTitle, outputFileBase, packageSpecificConfig, esbuild } = options ;
26+ const { bundleType, entrypoints, licenseTitle, outputFileBase, packageSpecificConfig } = options ;
2727
28- const nodeResolvePlugin = makeNodeResolvePlugin ( ) ;
29- const transpilePlugin = makeEsbuildPlugin ( esbuild ) ;
3028 const markAsBrowserBuildPlugin = makeBrowserBuildPlugin ( true ) ;
31- const licensePlugin = makeLicensePlugin ( licenseTitle ) ;
29+ const banner = makeBannerOptions ( licenseTitle , packageDotJSON . version ) ;
3230 const rrwebBuildPlugin = makeRrwebBuildPlugin ( {
3331 excludeIframe : false ,
3432 excludeShadowDom : false ,
3533 } ) ;
3634 const productionReplacePlugin = makeProductionReplacePlugin ( ) ;
3735
38- // The `commonjs` plugin is the `esModuleInterop` of the bundling world. When used with `transformMixedEsModules`, it
39- // will include all dependencies, imported or required, in the final bundle. (Without it, CJS modules aren't included
40- // at all, and without `transformMixedEsModules`, they're only included if they're imported, not if they're required.)
41- const commonJSPlugin = makeCommonJSPlugin ( { transformMixedEsModules : true } ) ;
42-
4336 // used by `@sentry/browser`
4437 const standAloneBundleConfig = {
4538 output : {
39+ banner,
4640 format : 'iife' ,
4741 name : 'Sentry' ,
4842 intro : ( ) => {
4943 return 'exports = window.Sentry || {};' ;
5044 } ,
5145 } ,
5246 context : 'window' ,
53- plugins : [ rrwebBuildPlugin , markAsBrowserBuildPlugin , licensePlugin ] ,
47+ plugins : [ rrwebBuildPlugin , markAsBrowserBuildPlugin ] ,
5448 } ;
5549
5650 // used by `@sentry/wasm` & pluggable integrations from core/browser (bundles which need to be combined with a stand-alone SDK bundle)
@@ -61,7 +55,7 @@ export function makeBaseBundleConfig(options) {
6155 format : 'cjs' ,
6256
6357 // code to add before the CJS wrapper
64- banner : ' (function (__window) {' ,
58+ banner : ` ${ banner } \n (function (__window) {` ,
6559
6660 // code to add just inside the CJS wrapper, before any of the wrapped code
6761 intro : 'var exports = {};' ,
@@ -84,30 +78,41 @@ export function makeBaseBundleConfig(options) {
8478 // code to add after the CJS wrapper
8579 footer : '}(window));' ,
8680 } ,
87- plugins : [ rrwebBuildPlugin , markAsBrowserBuildPlugin , licensePlugin ] ,
81+ plugins : [ rrwebBuildPlugin , markAsBrowserBuildPlugin ] ,
8882 } ;
8983
9084 const workerBundleConfig = {
9185 output : {
86+ banner,
9287 format : 'esm' ,
88+ minify : makeMinifierOptions ( ) ,
9389 } ,
94- plugins : [ commonJSPlugin , makeTerserPlugin ( ) , licensePlugin ] ,
9590 // Don't bundle any of Node's core modules
96- external : builtinModules ,
91+ external : getNodeBuiltIns ( ) ,
9792 } ;
9893
9994 const awsLambdaExtensionBundleConfig = {
10095 output : {
10196 format : 'esm' ,
97+ minify : makeMinifierOptions ( ) ,
10298 } ,
103- plugins : [ commonJSPlugin , makeIsDebugBuildPlugin ( true ) , makeTerserPlugin ( ) ] ,
99+ plugins : [ makeIsDebugBuildPlugin ( true ) ] ,
104100 // Don't bundle any of Node's core modules
105- external : builtinModules ,
101+ external : getNodeBuiltIns ( ) ,
106102 } ;
107103
108104 // used by all bundles
109105 const sharedBundleConfig = {
110106 input : entrypoints ,
107+
108+ // Point at the package's tsconfig so rolldown picks up its TypeScript & JSX settings.
109+ tsconfig : path . resolve ( process . cwd ( ) , './tsconfig.json' ) ,
110+
111+ // ES2020 is our floor: keeps `?.`/`??` native and downlevels everything newer.
112+ transform : {
113+ target : 'es2020' ,
114+ } ,
115+
111116 output : {
112117 // a file extension will be added to this base value when we specify either a minified or non-minified build
113118 entryFileNames : outputFileBase ,
@@ -116,8 +121,8 @@ export function makeBaseBundleConfig(options) {
116121 strict : false ,
117122 esModule : false ,
118123 } ,
119- plugins : [ productionReplacePlugin , transpilePlugin , nodeResolvePlugin ] ,
120- treeshake : 'smallest' ,
124+ plugins : [ productionReplacePlugin ] ,
125+ treeshake : treeShakePreset ( 'smallest' ) ,
121126 } ;
122127
123128 const bundleTypeConfigMap = {
@@ -147,7 +152,7 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
147152
148153 const includeDebuggingPlugin = makeIsDebugBuildPlugin ( true ) ;
149154 const stripDebuggingPlugin = makeIsDebugBuildPlugin ( false ) ;
150- const terserPlugin = makeTerserPlugin ( ) ;
155+ const minify = makeMinifierOptions ( ) ;
151156 const setSdkSourcePlugin = makeSetSDKSourcePlugin ( 'cdn' ) ;
152157
153158 // The additional options to use for each variant we're going to create.
@@ -162,15 +167,17 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
162167 '.min.js' : {
163168 output : {
164169 entryFileNames : chunkInfo => `${ baseConfig . output . entryFileNames ( chunkInfo ) } .min.js` ,
170+ minify,
165171 } ,
166- plugins : [ stripDebuggingPlugin , setSdkSourcePlugin , terserPlugin ] ,
172+ plugins : [ stripDebuggingPlugin , setSdkSourcePlugin ] ,
167173 } ,
168174
169175 '.debug.min.js' : {
170176 output : {
171177 entryFileNames : chunkInfo => `${ baseConfig . output . entryFileNames ( chunkInfo ) } .debug.min.js` ,
178+ minify,
172179 } ,
173- plugins : [ includeDebuggingPlugin , setSdkSourcePlugin , terserPlugin ] ,
180+ plugins : [ includeDebuggingPlugin , setSdkSourcePlugin ] ,
174181 } ,
175182 } ;
176183
0 commit comments