Skip to content

Commit a1e97ea

Browse files
authored
ref(build): Handle minification in rollup config generation function (#4681)
As part of the new build process, this removes minification config from being hardcoded in individual `rollup.config.js` files and instead uses a new function in the main `rollup.config.js` to generate minified and unminified variants of each build config it's given. This also includes a few other small changes: - Moved the license plugin to the main config function. - Removed exports which were no longer necessary now that most config is centralized. - Refactored individual `rollup.config.js` files to have more parallel structure. - Moved a comment and renamed the `markAsBrowserBulid` plugin so it has the work "plugin" in its name.
1 parent 61c79ef commit a1e97ea

File tree

6 files changed

+152
-228
lines changed

6 files changed

+152
-228
lines changed

packages/browser/rollup.config.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,17 @@
1-
import { makeBaseBundleConfig, makeLicensePlugin, terserPlugin } from '../../rollup.config';
1+
import { makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config';
22

33
const builds = [];
44

5-
const licensePlugin = makeLicensePlugin();
6-
75
['es5', 'es6'].forEach(jsVersion => {
86
const baseBundleConfig = makeBaseBundleConfig({
97
input: 'src/index.ts',
108
isAddOn: false,
119
jsVersion,
10+
licenseTitle: '@sentry/browser',
1211
outputFileBase: `build/bundle${jsVersion === 'es6' ? '.es6' : ''}`,
1312
});
1413

15-
builds.push(
16-
...[
17-
{
18-
...baseBundleConfig,
19-
output: {
20-
...baseBundleConfig.output,
21-
file: `${baseBundleConfig.output.file}.js`,
22-
},
23-
plugins: [...baseBundleConfig.plugins, licensePlugin],
24-
},
25-
{
26-
...baseBundleConfig,
27-
output: {
28-
...baseBundleConfig.output,
29-
file: `${baseBundleConfig.output.file}.min.js`,
30-
},
31-
plugins: [...baseBundleConfig.plugins, terserPlugin, licensePlugin],
32-
},
33-
],
34-
);
14+
builds.push(...makeMinificationVariants(baseBundleConfig));
3515
});
3616

3717
export default builds;

packages/integrations/rollup.config.js

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,25 @@ import * as fs from 'fs';
22

33
import commonjs from '@rollup/plugin-commonjs';
44

5-
import { makeBaseBundleConfig, terserPlugin } from '../../rollup.config';
6-
7-
function allIntegrations() {
8-
return fs.readdirSync('./src').filter(file => file != 'index.ts');
9-
}
10-
11-
function loadAllIntegrations() {
12-
const builds = [];
13-
14-
allIntegrations().forEach(file => {
15-
const baseBundleConfig = makeBaseBundleConfig({
16-
input: `src/${file}`,
17-
isAddOn: true,
18-
jsVersion: 'es5',
19-
outputFileBase: `build/${file.replace('.ts', '')}`,
20-
});
21-
22-
[
23-
{
24-
extension: '.js',
25-
plugins: [...baseBundleConfig.plugins, commonjs()],
26-
},
27-
{
28-
extension: '.min.js',
29-
plugins: [...baseBundleConfig.plugins, commonjs(), terserPlugin],
30-
},
31-
].forEach(build => {
32-
builds.push({
33-
...baseBundleConfig,
34-
output: {
35-
...baseBundleConfig.output,
36-
file: `${baseBundleConfig.output.file}${build.extension}`,
37-
},
38-
plugins: build.plugins,
39-
});
40-
});
5+
import { insertAt, makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config';
6+
7+
const builds = [];
8+
9+
const integrationSourceFiles = fs.readdirSync('./src').filter(file => file != 'index.ts');
10+
11+
integrationSourceFiles.forEach(file => {
12+
const baseBundleConfig = makeBaseBundleConfig({
13+
input: `src/${file}`,
14+
isAddOn: true,
15+
jsVersion: 'es5',
16+
licenseTitle: '@sentry/integrations',
17+
outputFileBase: `build/${file.replace('.ts', '')}`,
4118
});
4219

43-
return builds;
44-
}
20+
// TODO We only need `commonjs` for localforage (used in the offline plugin). Once that's fixed, this can come out.
21+
baseBundleConfig.plugins = insertAt(baseBundleConfig.plugins, -2, commonjs());
22+
23+
builds.push(...makeMinificationVariants(baseBundleConfig));
24+
});
4525

46-
export default loadAllIntegrations();
26+
export default builds;

packages/tracing/rollup.config.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,17 @@
1-
import { makeBaseBundleConfig, makeLicensePlugin, terserPlugin } from '../../rollup.config';
1+
import { makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config';
22

33
const builds = [];
44

5-
const licensePlugin = makeLicensePlugin('@sentry/tracing & @sentry/browser');
6-
75
['es5', 'es6'].forEach(jsVersion => {
86
const baseBundleConfig = makeBaseBundleConfig({
97
input: 'src/index.bundle.ts',
108
isAddOn: false,
119
jsVersion,
10+
licenseTitle: '@sentry/tracing & @sentry/browser',
1211
outputFileBase: `build/bundle.tracing${jsVersion === 'es6' ? '.es6' : ''}`,
1312
});
1413

15-
builds.push(
16-
...[
17-
{
18-
...baseBundleConfig,
19-
output: {
20-
...baseBundleConfig.output,
21-
file: `${baseBundleConfig.output.file}.js`,
22-
},
23-
plugins: [...baseBundleConfig.plugins, licensePlugin],
24-
},
25-
{
26-
...baseBundleConfig,
27-
output: {
28-
...baseBundleConfig.output,
29-
file: `${baseBundleConfig.output.file}.min.js`,
30-
},
31-
plugins: [...baseBundleConfig.plugins, terserPlugin, licensePlugin],
32-
},
33-
],
34-
);
14+
builds.push(...makeMinificationVariants(baseBundleConfig));
3515
});
3616

3717
export default builds;

packages/vue/rollup.config.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
1-
import { makeBaseBundleConfig, makeLicensePlugin, terserPlugin } from '../../rollup.config';
2-
3-
const licensePlugin = makeLicensePlugin();
1+
import { makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config';
42

53
const baseBundleConfig = makeBaseBundleConfig({
64
input: 'src/index.bundle.ts',
75
isAddOn: false,
86
jsVersion: 'es5',
7+
licenseTitle: '@sentry/vue',
98
outputFileBase: 'build/bundle.vue',
109
});
1110

12-
export default [
13-
{
14-
...baseBundleConfig,
15-
output: {
16-
...baseBundleConfig.output,
17-
file: `${baseBundleConfig.output.file}.js`,
18-
},
19-
plugins: [...baseBundleConfig.plugins, licensePlugin],
20-
},
21-
{
22-
...baseBundleConfig,
23-
output: {
24-
...baseBundleConfig.output,
25-
file: `${baseBundleConfig.output.file}.min.js`,
26-
},
27-
plugins: [...baseBundleConfig.plugins, terserPlugin, licensePlugin],
28-
},
29-
];
11+
export default makeMinificationVariants(baseBundleConfig);

packages/wasm/rollup.config.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,11 @@
1-
import { makeBaseBundleConfig, terserPlugin } from '../../rollup.config';
1+
import { makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config';
22

33
const baseBundleConfig = makeBaseBundleConfig({
44
input: 'src/index.ts',
55
isAddOn: true,
66
jsVersion: 'es5',
7+
licenseTitle: '@sentry/wasm',
78
outputFileBase: 'build/wasm',
89
});
910

10-
function loadAllIntegrations() {
11-
const builds = [];
12-
[
13-
{
14-
extension: '.js',
15-
plugins: baseBundleConfig.plugins,
16-
},
17-
{
18-
extension: '.min.js',
19-
plugins: [...baseBundleConfig.plugins, terserPlugin],
20-
},
21-
].forEach(build => {
22-
builds.push({
23-
...baseBundleConfig,
24-
output: {
25-
...baseBundleConfig.output,
26-
file: `${baseBundleConfig.output.file}${build.extension}`,
27-
},
28-
plugins: build.plugins,
29-
});
30-
});
31-
return builds;
32-
}
33-
34-
export default loadAllIntegrations();
11+
export default makeMinificationVariants(baseBundleConfig);

0 commit comments

Comments
 (0)