From 5adda1deef7659e50f3e03f01c0e97e0b37087b9 Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Sun, 15 Jul 2018 07:58:08 -0700 Subject: [PATCH] Introduce config.modifyBabelOptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’ve found that the babel configuration is important to modify in my environment. Specifically in my env, I’d like to set `babelrc: false` so that the .babelrc file is ignored, and a custom babel configuration could be provided in the `razzle.config.js`. --- packages/razzle/config/createConfig.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/razzle/config/createConfig.js b/packages/razzle/config/createConfig.js index abf0a79ad..5b6254193 100644 --- a/packages/razzle/config/createConfig.js +++ b/packages/razzle/config/createConfig.js @@ -37,7 +37,14 @@ const postCssOptions = { module.exports = ( target = 'web', env = 'dev', - { clearConsole = true, host = 'localhost', port = 3000, modify, plugins }, + { + clearConsole = true, + host = 'localhost', + port = 3000, + modify, + plugins, + modifyBabelOptions, + }, webpackObject ) => { // First we check to see if the user has a custom .babelrc file, otherwise @@ -58,12 +65,19 @@ module.exports = ( useEslintrc: true, }; - if (hasBabelRc) { - console.log('Using .babelrc defined in your app root'); - } else { + if (!hasBabelRc) { mainBabelOptions.presets.push(require.resolve('../babel')); } + // Allow app to override babel options + const babelOptions = modifyBabelOptions + ? modifyBabelOptions(mainBabelOptions) + : mainBabelOptions; + + if (hasBabelRc && babelOptions.babelrc) { + console.log('Using .babelrc defined in your app root'); + } + if (hasEslintRc) { console.log('Using .eslintrc defined in your app root'); } else { @@ -135,7 +149,7 @@ module.exports = ( use: [ { loader: require.resolve('babel-loader'), - options: mainBabelOptions, + options: babelOptions, }, ], },