diff --git a/modules/dev-tools/docs/api-reference/get-babel-config.md b/modules/dev-tools/docs/api-reference/get-babel-config.md index 0eec37d6..e832460d 100644 --- a/modules/dev-tools/docs/api-reference/get-babel-config.md +++ b/modules/dev-tools/docs/api-reference/get-babel-config.md @@ -21,3 +21,13 @@ module.exports = getBabelConfig({ debug: true }); ``` + +## Environments + +The following environments may be used by various commands: + +- `es5` - default commonjs entry point for non-ESM module used by `ocular-build` +- `esm` - default ESM entry point for non-ESM module used by `ocular-build` +- `esm-strict` - default ESM entry point for ESM module used by `ocular-build` +- `bundle` - production bundle settings used by `ocular-bundle` +- `bundle-dev` - developer bundle settings used by `ocular-bundle --env=dev` diff --git a/modules/dev-tools/src/configuration/esbuild.config.js b/modules/dev-tools/src/configuration/esbuild.config.js index b1778d9e..84bb1306 100644 --- a/modules/dev-tools/src/configuration/esbuild.config.js +++ b/modules/dev-tools/src/configuration/esbuild.config.js @@ -37,18 +37,20 @@ function getExternalGlobalsIIFE(externalPackages, mapping) { } /** Evaluate root babel config */ -async function getBabelConfigProd(configPath, target) { +async function getBabelConfig(configPath, env, target) { let config = await import(configPath); if (config.default) { config = config.default; } if (typeof config === 'function') { config = config({ - env: () => 'bundle' + env: () => env }); } - if (target) { - config.presets.find((item) => item[0] === '@babel/env')[1].targets = target; + const envPreset = config.presets.find((item) => item[0] === '@babel/env'); + if (target && envPreset) { + envPreset[1] = envPreset[1] || {}; + envPreset[1].targets = target; } return config; } @@ -107,20 +109,15 @@ export default async function getBundleConfig(opts) { sourcemap = false } = opts; - let babelConfig; - if (devMode) { - babelConfig = { - filter: /src|bundle/, - config: { - presets: ['@babel/preset-typescript', '@babel/preset-react'] + const babelConfig = devMode + ? { + filter: /src|bundle/, + config: await getBabelConfig(ocularConfig.babel.configPath, 'bundle-dev', target) } - }; - } else { - babelConfig = { - filter: /src|bundle|esm/, - config: await getBabelConfigProd(ocularConfig.babel.configPath, target) - }; - } + : { + filter: /src|bundle|esm/, + config: await getBabelConfig(ocularConfig.babel.configPath, 'bundle', target) + }; let externalPackages = Object.keys(packageInfo.peerDependencies || {}); if (typeof externals === 'string') { diff --git a/modules/dev-tools/src/configuration/get-babel-config.cjs b/modules/dev-tools/src/configuration/get-babel-config.cjs index ad24dd52..d9bb49ff 100644 --- a/modules/dev-tools/src/configuration/get-babel-config.cjs +++ b/modules/dev-tools/src/configuration/get-babel-config.cjs @@ -96,11 +96,12 @@ const ENV_CONFIG = { modules: false } ] - ], - plugins: [ - '@babel/transform-runtime' ] }, + + 'bundle-dev': { + presets: [...COMMON_PRESETS] + } }; // Ensure we have an entry for the default BABEL_ENV