Skip to content

Commit 5b1ff8c

Browse files
ericvicentijaredpalmer
authored andcommitted
Introduce config.modifyBabelOptions (#702)
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`.
1 parent 5475aef commit 5b1ff8c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

packages/razzle/config/createConfig.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ const postCssOptions = {
3737
module.exports = (
3838
target = 'web',
3939
env = 'dev',
40-
{ clearConsole = true, host = 'localhost', port = 3000, modify, plugins },
40+
{
41+
clearConsole = true,
42+
host = 'localhost',
43+
port = 3000,
44+
modify,
45+
plugins,
46+
modifyBabelOptions,
47+
},
4148
webpackObject
4249
) => {
4350
// First we check to see if the user has a custom .babelrc file, otherwise
@@ -58,12 +65,19 @@ module.exports = (
5865
useEslintrc: true,
5966
};
6067

61-
if (hasBabelRc) {
62-
console.log('Using .babelrc defined in your app root');
63-
} else {
68+
if (!hasBabelRc) {
6469
mainBabelOptions.presets.push(require.resolve('../babel'));
6570
}
6671

72+
// Allow app to override babel options
73+
const babelOptions = modifyBabelOptions
74+
? modifyBabelOptions(mainBabelOptions)
75+
: mainBabelOptions;
76+
77+
if (hasBabelRc && babelOptions.babelrc) {
78+
console.log('Using .babelrc defined in your app root');
79+
}
80+
6781
if (hasEslintRc) {
6882
console.log('Using .eslintrc defined in your app root');
6983
} else {
@@ -135,7 +149,7 @@ module.exports = (
135149
use: [
136150
{
137151
loader: require.resolve('babel-loader'),
138-
options: mainBabelOptions,
152+
options: babelOptions,
139153
},
140154
],
141155
},

0 commit comments

Comments
 (0)