1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Babelrc false babelrc (#1094)

* Detect babelrc disabling via babelrc.

* Simplify boolean condition.
This commit is contained in:
Arunoda Susiripala 2017-02-13 02:48:22 +05:30 committed by Naoyuki Kanezawa
parent a0453a7b84
commit b220193167
3 changed files with 17 additions and 9 deletions

View file

@ -1,3 +1,3 @@
{
"presets": ["../babel"]
"babelrc": false
}

View file

@ -1,7 +1,7 @@
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]
}

View file

@ -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',