-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathget-babel-config.js
42 lines (40 loc) · 1.16 KB
/
get-babel-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
module.exports = ( environment = '', file ) => {
/*
* Specific options to be passed using the caller config option:
* https://babeljs.io/docs/en/options#caller
*
* The caller options can only be 'boolean', 'string', or 'number' by design:
* https://github.com/babel/babel/blob/bd0c62dc0c30cf16a4d4ef0ddf21d386f673815c/packages/babel-core/src/config/validation/option-assertions.js#L122
*/
const callerOpts = {
caller: {
name: `WP_BUILD_${ environment.toUpperCase() }`,
},
};
// Add `/* wp:polyfill */` magic comment where needed.
callerOpts.caller.addPolyfillComments = true;
switch ( environment ) {
case 'main':
// To be merged as a presetEnv option.
callerOpts.caller.modules = 'commonjs';
break;
case 'module':
// To be merged as a presetEnv option.
callerOpts.caller.modules = false;
// To be merged as a pluginTransformRuntime option.
callerOpts.caller.useESModules = true;
break;
default:
// Preventing measure, this shouldn't happen ever.
delete callerOpts.caller;
}
// Sourcemaps options.
const sourceMapsOpts = {
sourceMaps: true,
sourceFileName: file,
};
return {
...callerOpts,
...sourceMapsOpts,
};
};