-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
bento-element-config.js
70 lines (63 loc) · 1.74 KB
/
bento-element-config.js
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
const {
getSharedBentoSymbols,
} = require('../compile/generate/shared-bento-symbols');
const {generateIntermediatePackage} = require('../compile/generate/bento');
const {getMinifiedConfig} = require('./minified-config');
const {getUnminifiedConfig} = require('./unminified-config');
const {outputFileSync} = require('fs-extra');
let modulePath;
/**
* @param {{[name: string]: string[]}} packages
* @return {string}
*/
function writeIntermediatePackage(packages) {
if (!modulePath) {
// Don't remove the `./`
modulePath = './build/bento-shared.js';
outputFileSync(modulePath, generateIntermediatePackage(packages));
}
return modulePath;
}
/**
* @param {{[name: string]: string[]}} packages
* @return {[string, {root: string[], alias: {[alias: string]: string}}, string]}
*/
function getModuleResolver(packages) {
const modulePath = writeIntermediatePackage(packages);
const alias = Object.fromEntries(
Object.entries(packages).map(([name]) => [`^${name}$`, modulePath])
);
return [
'module-resolver',
{root: ['.'], alias},
// Unique name because "module-resolver" is used elsewhere and babel will
// throw a duplicate name error.
'module-resolver-bento-shared',
];
}
/**
* @param {!Object} config
* @return {Object}
*/
function withModuleResolver(config) {
return {
...config,
plugins: [getModuleResolver(getSharedBentoSymbols()), ...config.plugins],
};
}
/**
* @return {!Object}
*/
function getBentoElementUnminifiedConfig() {
return withModuleResolver(getUnminifiedConfig());
}
/**
* @return {!Object}
*/
function getBentoElementMinifiedConfig() {
return withModuleResolver(getMinifiedConfig());
}
module.exports = {
getBentoElementUnminifiedConfig,
getBentoElementMinifiedConfig,
};