diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 758c6472..77f86aaf 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -396,7 +396,7 @@ class WebpackConfig { } if (this.doesBabelRcFileExist()) { - logger.warning('The "callback" argument of configureBabel() will not be used because your app already provides an external Babel configuration (a ".babelrc" file, ".babelrc.js" file or "babel" key in "package.json"). Use null as a first argument to remove that warning.'); + logger.warning('The "callback" argument of configureBabel() will not be used because your app already provides an external Babel configuration (e.g. a ".babelrc" or "babelrc.config.js" file or "babel" key in "package.json"). Use null as a first argument to remove that warning.'); } } @@ -415,7 +415,7 @@ class WebpackConfig { } if (this.doesBabelRcFileExist() && !allowedOptionsWithExternalConfig.includes(normalizedOptionKey)) { - logger.warning(`The "${normalizedOptionKey}" option of configureBabel() will not be used because your app already provides an external Babel configuration (a ".babelrc" file, ".babelrc.js" file or "babel" key in "package.json").`); + logger.warning(`The "${normalizedOptionKey}" option of configureBabel() will not be used because your app already provides an external Babel configuration (e.g. a ".babelrc" or "babelrc.config.js" file or "babel" key in "package.json").`); continue; } @@ -462,7 +462,7 @@ class WebpackConfig { } if (this.doesBabelRcFileExist()) { - throw new Error('The "callback" argument of configureBabelPresetEnv() will not be used because your app already provides an external Babel configuration (a ".babelrc" file, ".babelrc.js" file or "babel" key in "package.json").'); + throw new Error('The "callback" argument of configureBabelPresetEnv() will not be used because your app already provides an external Babel configuration (e.g. a ".babelrc" or "babelrc.config.js" file or "babel" key in "package.json").'); } this.babelPresetEnvOptionsCallback = callback; diff --git a/lib/config/parse-runtime.js b/lib/config/parse-runtime.js index 34f726d6..2294c64b 100644 --- a/lib/config/parse-runtime.js +++ b/lib/config/parse-runtime.js @@ -87,21 +87,21 @@ module.exports = function(argv, cwd) { const partialConfig = babel.loadPartialConfig({ /* - * This is a small mystery. Even if we set the cwd & root - * options, deep in babel, if the filename option is not - * set, then it doesn't see the "cwd" directory as a valid - * directory where it should look for the .babelrc file. - * The fact that this is set to webpack.config.js is not - * significant at all - you could even invent a filename. - * However, as I'm not sure the side effects (the filename - * option is documented as "for error messages"), we're - * setting it to a realistic filename. + * There are two types of babel configuration: + * - project-wide configuration in babel.config.* files + * - file-relative configuration in .babelrc.* files + * or package.json files with a "babel" key + * + * To detect the file-relative configuration we need + * to set the following values. The filename is needed + * for Babel as an example so that it knows where it + * needs to search the relative config for. */ root: cwd, cwd: cwd, filename: path.join(cwd, 'webpack.config.js') }); - runtimeConfig.babelRcFileExists = (typeof partialConfig.babelrc === 'string'); + runtimeConfig.babelRcFileExists = partialConfig.hasFilesystemConfig(); return runtimeConfig; }; diff --git a/test/config/parse-runtime.js b/test/config/parse-runtime.js index 36531f5b..90575e31 100644 --- a/test/config/parse-runtime.js +++ b/test/config/parse-runtime.js @@ -96,6 +96,18 @@ describe('parse-runtime', () => { expect(config.context).to.equal('/tmp/custom-context'); }); + it('babel config in package.json detected when present', () => { + const projectDir = createTestDirectory(); + fs.writeFileSync( + path.join(projectDir, 'package.json'), + '{"babel": {}}' + ); + + const config = parseArgv(createArgv(['dev']), projectDir); + + expect(config.babelRcFileExists).to.be.true; + }); + it('.babelrc detected when present', () => { const projectDir = createTestDirectory(); fs.writeFileSync( @@ -108,6 +120,18 @@ describe('parse-runtime', () => { expect(config.babelRcFileExists).to.be.true; }); + it('babel.config.json detected when present', () => { + const projectDir = createTestDirectory(); + fs.writeFileSync( + path.join(projectDir, 'babel.config.json'), + '{}' + ); + + const config = parseArgv(createArgv(['dev']), projectDir); + + expect(config.babelRcFileExists).to.be.true; + }); + it('dev-server command hot', () => { const testDir = createTestDirectory(); const config = parseArgv(createArgv(['dev-server', '--hot']), testDir);