diff --git a/packages/website/babel.config.js b/packages/website/babel.config.js index 91792cc..946c391 100644 --- a/packages/website/babel.config.js +++ b/packages/website/babel.config.js @@ -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', @@ -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; diff --git a/packages/website/package.json b/packages/website/package.json index fd68cfd..b41c8be 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -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",