embark/babel.config.js
Pascal Precht 96b6dd27c0
refactor(@embark/core): move Engine into embark-core
This also moves other modules and packages into `embark-core` which are
affected by the move of `Engine`.

It did some clean-up of some modules (e.g. `lib/utils/utils.js` had a lot of
stuff that was not used anywhere).

This is the first step to start typing our core inside out. For now we're just
moving code into their dedicated package, after that we can address making
use of TypeScript features as we see fit.
2019-11-08 14:51:48 +01:00

86 lines
2.0 KiB
JavaScript

/* global module require */
/*
* dependencies of this config should be specified in
* `utils/collective/package.json` relative to this config file, with reliance
* on yarn-workspace hoisting for those packages to be resolvable from the
* monorepo root
*/
const cloneDeep = require('lodash.clonedeep');
module.exports = (api) => {
const env = api.env();
const base = {
babelrcRoots: [
'.',
'packages/*'
],
plugins: [
'babel-plugin-macros',
['@babel/plugin-proposal-decorators', {
legacy: true
}],
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-syntax-dynamic-import',
['@babel/plugin-proposal-class-properties', {
loose: true
}],
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining',
['@babel/plugin-transform-runtime', {
corejs: 3
}]
],
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], {
corejs: 3,
modules: false,
shippedProposals: true,
targets: {browsers: ['last 1 version', 'not dead', '> 0.2%']},
useBuiltIns: 'usage'
}];
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], {
corejs: 3,
shippedProposals: true,
targets: {node: '10.17.0'},
useBuiltIns: 'usage'
}];
if (env === 'node' || env.startsWith('node:')) {
return node;
}
const test = cloneDeep(node);
if (env === 'test') {
return test;
}
return {};
};