Commit b2201931 authored by Arunoda Susiripala's avatar Arunoda Susiripala Committed by Naoyuki Kanezawa

Babelrc false babelrc (#1094)

* Detect babelrc disabling via babelrc.

* Simplify boolean condition.
parent a0453a7b
{
"presets": ["../babel"]
"babelrc": false
}
\ No newline at end of file
import { join } from 'path'
import buildConfigChain from 'babel-core/lib/transformation/file/options/build-config-chain'
export default function findBabelConfigLocation (dir) {
export default function findBabelConfig (dir) {
// We need to provide a location of a filename inside the `dir`.
// For the name of the file, we could be provide anything.
const filename = join(dir, 'filename.js')
......@@ -12,5 +12,5 @@ export default function findBabelConfigLocation (dir) {
// That's the config we are passing as the "options" below
const configList = buildConfigChain(options).filter(i => i.loc !== 'base')
return configList[0] ? configList[0].loc : null
return configList[0]
}
......@@ -10,7 +10,7 @@ import WatchPagesPlugin from './plugins/watch-pages-plugin'
import JsonPagesPlugin from './plugins/json-pages-plugin'
import getConfig from '../config'
import * as babelCore from 'babel-core'
import findBabelConfigLocation from './babel/find-config-location'
import findBabelConfig from './babel/find-config'
const documentPage = join('pages', '_document.js')
const defaultPages = [
......@@ -114,16 +114,24 @@ export default async function createCompiler (dir, { dev = false, quiet = false
presets: []
}
const configLocation = findBabelConfigLocation(dir)
if (configLocation) {
const externalBabelConfig = findBabelConfig(dir)
if (externalBabelConfig) {
console.log(`> Using external babel configuration`)
console.log(`> location: "${configLocation}"`)
mainBabelOptions.babelrc = true
console.log(`> location: "${externalBabelConfig.loc}"`)
// It's possible to turn off babelrc support via babelrc itself.
// In that case, we should add our default preset.
// That's why we need to do this.
const { options } = externalBabelConfig
mainBabelOptions.babelrc = options.babelrc !== false
} else {
mainBabelOptions.presets.push(require.resolve('./babel/preset'))
mainBabelOptions.babelrc = false
}
// Add our default preset if the no "babelrc" found.
if (!mainBabelOptions.babelrc) {
mainBabelOptions.presets.push(require.resolve('./babel/preset'))
}
const rules = (dev ? [{
test: /\.js(\?[^?]*)?$/,
loader: 'hot-self-accept-loader',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment