/
rollup.config.mjs
89 lines (75 loc) · 2.37 KB
/
rollup.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import {
commonRollupConfig,
makeReviewBoardRollupConfig
} from '@beanbag/reviewboard/packaging/js/rollup-common.mjs';
/*
* Configuration for the 3rdparty-base bundle.
*
* This bundle provides only a couple of base modules that we want to make
* sure are loaded before anything else.
*
* This will require a combination of CommonJS and ES6 modules, coming from
* node_modules.
*/
const thirdPartyBaseConfig = {
output: commonRollupConfig.output,
plugins: [
/* This must take place before babel(). */
commonjs(commonRollupConfig.plugins.commonjs),
/* Configure rollup to use Babel to compile files. */
babel(commonRollupConfig.plugins.babel),
/* Specify where modules should be looked up from. */
resolve(commonRollupConfig.plugins.resolve),
],
treeshake: commonRollupConfig.treeshake,
};
/**
* Configuration for all other lib bundles (3rdparty and others).
*
* These are dependent on 3rdparty-base.
*/
function makeThirdPartyConfig(input) {
return {
...thirdPartyBaseConfig,
external: commonRollupConfig.external,
input: input,
output: {
...thirdPartyBaseConfig.output,
globals: commonRollupConfig.globals,
},
};
}
/**
* Configuration for the rest of the Review Board (and Djblets) codebases.
*
* These are set up to reference the external libraries from the lib bundles
* as globals, ensuring we don't end up bundling them unintentionally.
*/
const rbConfig = makeReviewBoardRollupConfig({
output: {
/*
* Anything exported from a top-level index.* file (as specified in
* the Pipeline bundle configuration) will be placed in this top-level
* variable.
*/
name: 'RB',
},
modulePaths: [
'reviewboard/static/lib/js',
'reviewboard/static/rb/js',
'.npm-workspaces/djblets/static/djblets/js',
],
});
export default args => {
const input = (args.input || [''])[0];
if (input.includes('reviewboard/static/lib/js/3rdparty-base/')) {
return thirdPartyBaseConfig;
} else if (input.includes('reviewboard/static/lib/')) {
return makeThirdPartyConfig(input);
} else {
return rbConfig;
}
};