Skip to content

Issue/afp 246 external babelconfig support #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion packages/website/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
module.exports = {
const fse = require('fs-extra');
const path = require('path');

const handleConfig = require('./bin/handle-config');

const configPath = process.env.DOCS_WEBSITE_CONFIG_PATH;
const cwd = process.env.DOCS_WEBSITE_CWD;

if (!cwd) {
throw new Error('DOCS_WEBSITE_CWD is not defined');
}

const { babelConfig: clientBabelConfig, loadBabel } = handleConfig(
cwd,
configPath,
);

let babelConfig = {
presets: ['next/babel', '@zeit/next-typescript/babel'],
plugins: [
'emotion',
Expand All @@ -16,3 +33,19 @@ module.exports = {
'transform-dynamic-import',
],
};

// to merge the consumer level babel.config
// condition required to support dev testing of our website which otherwise throws Configuration cycle detected loading error.
// if the consumer provides a babel.config extend here
if (
cwd !== __dirname &&
clientBabelConfig &&
fse.existsSync(path.resolve(cwd, clientBabelConfig))
) {
babelConfig.extends = path.resolve(cwd, clientBabelConfig);
} else if (loadBabel) {
// option to pass the required babel configs as function suppose the above scenario is not supported for a consumer.
babelConfig = loadBabel(babelConfig);
}

module.exports = babelConfig;
3 changes: 3 additions & 0 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
"@babel/core": "^7.0.0-0",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@brisk-docs/react-changelogs": "0.1.3",
"@emotion/core": "^10.0.9",
Expand Down