mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-09 05:23:26 +00:00
3f61e314d9
Setup a `babel.config.js` in the root of the monorepo to be used by `packages/*`. It won't be used by some packages, e.g. `packages/embark-ui`, but most of them should use it instead of rolling their own. Allow for package-level modifications by specifying `babelrcRoots` in the root `babel.config.js` Use the babel `--root-mode upward` option in `packages/embark`'s `build` script. Other packages intending to use the common config should do likewise. Use a `.babelrc.js` in `packages/embark` to supply the package-specific `ignore` settings. Make packages used by the common config devDeps of the root. Extract babel-related devDeps from `packages/embark`, but don't extract the non-dev deps since those are used by embark's pipeline in a production install. Normally, it should only be necessary to have `@babel/cli` and `@babel/core` in devDeps, and possibly `@babel/runtime-corejs2` in deps, plus any package-specific babel-related dev/deps. Once we deprecate the pipeline, we can finish the extraction. Use `ncu -f '/babel/' -u` to bump the versions of all babel-related deps in the root and in `packages/embark`. We get better space/time savings from the yarn workspace when versions match.
64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
/* global module require */
|
|
|
|
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-syntax-dynamic-import',
|
|
['@babel/plugin-proposal-class-properties', {
|
|
loose: true
|
|
}],
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
['@babel/plugin-transform-runtime', {
|
|
corejs: 2
|
|
}]
|
|
],
|
|
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], {
|
|
modules: false,
|
|
targets: {browsers: ['last 1 version', 'not dead', '> 0.2%']}
|
|
}];
|
|
|
|
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], {
|
|
targets: {node: '8.11.3'}
|
|
}];
|
|
|
|
if (env === 'node' || env.startsWith('node:')) {
|
|
return node;
|
|
}
|
|
|
|
return {};
|
|
};
|