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 { join } from 'path'
import buildConfigChain from 'babel-core/lib/transformation/file/options/build-config-chain' 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`. // We need to provide a location of a filename inside the `dir`.
// For the name of the file, we could be provide anything. // For the name of the file, we could be provide anything.
const filename = join(dir, 'filename.js') const filename = join(dir, 'filename.js')
...@@ -12,5 +12,5 @@ export default function findBabelConfigLocation (dir) { ...@@ -12,5 +12,5 @@ export default function findBabelConfigLocation (dir) {
// That's the config we are passing as the "options" below // That's the config we are passing as the "options" below
const configList = buildConfigChain(options).filter(i => i.loc !== 'base') 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' ...@@ -10,7 +10,7 @@ import WatchPagesPlugin from './plugins/watch-pages-plugin'
import JsonPagesPlugin from './plugins/json-pages-plugin' import JsonPagesPlugin from './plugins/json-pages-plugin'
import getConfig from '../config' import getConfig from '../config'
import * as babelCore from 'babel-core' 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 documentPage = join('pages', '_document.js')
const defaultPages = [ const defaultPages = [
...@@ -114,16 +114,24 @@ export default async function createCompiler (dir, { dev = false, quiet = false ...@@ -114,16 +114,24 @@ export default async function createCompiler (dir, { dev = false, quiet = false
presets: [] presets: []
} }
const configLocation = findBabelConfigLocation(dir) const externalBabelConfig = findBabelConfig(dir)
if (configLocation) { if (externalBabelConfig) {
console.log(`> Using external babel configuration`) console.log(`> Using external babel configuration`)
console.log(`> location: "${configLocation}"`) console.log(`> location: "${externalBabelConfig.loc}"`)
mainBabelOptions.babelrc = true // 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 { } else {
mainBabelOptions.presets.push(require.resolve('./babel/preset'))
mainBabelOptions.babelrc = false 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 ? [{ const rules = (dev ? [{
test: /\.js(\?[^?]*)?$/, test: /\.js(\?[^?]*)?$/,
loader: 'hot-self-accept-loader', 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