2019-02-05 20:29:51 +00:00
|
|
|
/* global module require */
|
|
|
|
|
2019-09-18 19:30:41 +00:00
|
|
|
/*
|
2020-01-29 22:19:25 +00:00
|
|
|
* dependencies of this config should be specified in `./package.json` relative
|
|
|
|
* to this config file (which should be in the root of the monorepo);
|
|
|
|
* yarn-workspace hoisting re: dev/Deps specified in
|
|
|
|
* `packages/utils/collective/package.json` is not reliable re: dependencies of
|
|
|
|
* this root-level config being resolvable (with correct versions) from the
|
2019-09-18 19:30:41 +00:00
|
|
|
* monorepo root
|
|
|
|
*/
|
|
|
|
|
2019-02-05 20:29:51 +00:00
|
|
|
const cloneDeep = require('lodash.clonedeep');
|
|
|
|
|
|
|
|
module.exports = (api) => {
|
|
|
|
const env = api.env();
|
|
|
|
|
|
|
|
const base = {
|
|
|
|
babelrcRoots: [
|
|
|
|
'.',
|
2019-09-07 00:02:31 +00:00
|
|
|
'packages/*'
|
2019-02-05 20:29:51 +00:00
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
'babel-plugin-macros',
|
|
|
|
['@babel/plugin-proposal-decorators', {
|
|
|
|
legacy: true
|
|
|
|
}],
|
2019-11-11 13:41:40 +00:00
|
|
|
'@babel/plugin-proposal-export-namespace-from',
|
|
|
|
'@babel/plugin-proposal-export-default-from',
|
2019-02-05 20:29:51 +00:00
|
|
|
'@babel/plugin-syntax-dynamic-import',
|
|
|
|
['@babel/plugin-proposal-class-properties', {
|
|
|
|
loose: true
|
|
|
|
}],
|
2019-10-24 21:41:28 +00:00
|
|
|
'@babel/plugin-proposal-nullish-coalescing-operator',
|
2019-02-05 20:29:51 +00:00
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
|
|
['@babel/plugin-transform-runtime', {
|
2019-10-24 21:41:28 +00:00
|
|
|
corejs: 3
|
2019-02-05 20:29:51 +00:00
|
|
|
}]
|
|
|
|
],
|
|
|
|
presets: [
|
|
|
|
'@babel/preset-env',
|
|
|
|
'@babel/preset-typescript'
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
if (env === 'base' || env.startsWith('base:')) {
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
const browser = cloneDeep(base);
|
|
|
|
browser.plugins[browser.plugins.length - 1][1].useESModules = true;
|
|
|
|
browser.presets[0] = [browser.presets[0], {
|
2019-10-24 21:41:28 +00:00
|
|
|
corejs: 3,
|
2019-02-05 20:29:51 +00:00
|
|
|
modules: false,
|
2019-10-24 21:41:28 +00:00
|
|
|
shippedProposals: true,
|
|
|
|
targets: {browsers: ['last 1 version', 'not dead', '> 0.2%']},
|
|
|
|
useBuiltIns: 'usage'
|
2019-02-05 20:29:51 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
if (env === 'browser' || env.startsWith('browser:')) {
|
|
|
|
return browser;
|
|
|
|
}
|
|
|
|
|
|
|
|
const node = cloneDeep(base);
|
|
|
|
node.plugins.splice(
|
|
|
|
node.plugins.indexOf('@babel/plugin-syntax-dynamic-import') + 1,
|
|
|
|
0,
|
|
|
|
'babel-plugin-dynamic-import-node'
|
|
|
|
);
|
|
|
|
node.presets[0] = [node.presets[0], {
|
2019-10-24 21:41:28 +00:00
|
|
|
corejs: 3,
|
|
|
|
shippedProposals: true,
|
|
|
|
targets: {node: '10.17.0'},
|
|
|
|
useBuiltIns: 'usage'
|
2019-02-05 20:29:51 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
if (env === 'node' || env.startsWith('node:')) {
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2019-09-13 02:06:23 +00:00
|
|
|
const test = cloneDeep(node);
|
|
|
|
|
|
|
|
if (env === 'test') {
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
2019-02-05 20:29:51 +00:00
|
|
|
return {};
|
|
|
|
};
|