Skip to content

Commit

Permalink
fix: babel 7 compat (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored and eddyerburgh committed Jan 15, 2018
1 parent ec223e6 commit cd39ea7
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 157 deletions.
11 changes: 10 additions & 1 deletion lib/compilers/babel-compiler.js
Expand Up @@ -2,12 +2,21 @@ const babel = require('babel-core')
const loadBabelConfig = require('../load-babel-config.js')

module.exports = function compileBabel (scriptContent, inputSourceMap) {
const babelConfig = loadBabelConfig()

if (!babelConfig) {
return {
code: scriptContent,
sourceMap: inputSourceMap
}
}

const sourceMapOptions = {
sourceMaps: true,
inputSourceMap: inputSourceMap
}

const babelOptions = Object.assign(sourceMapOptions, loadBabelConfig())
const babelOptions = Object.assign(sourceMapOptions, babelConfig)

const res = babel.transform(scriptContent, babelOptions)

Expand Down
15 changes: 7 additions & 8 deletions lib/load-babel-config.js
Expand Up @@ -2,21 +2,20 @@ const findBabelConfig = require('find-babel-config')
const logger = require('./logger')
const cache = require('./cache')

var defaultBabelOptions = {
presets: [require.resolve('babel-preset-vue-app')]
}

module.exports = function getBabelConfig () {
const cachedConfig = cache.get('babel-config')
if (cachedConfig) {
return cachedConfig
} else if (cachedConfig === false) {
return
} else {
const { file, config } = findBabelConfig.sync(process.cwd(), 0)
if (!file) {
logger.info('no .babelrc found, defaulting to default babel options')
logger.info('no .babelrc found, skipping babel compilation')
cache.set('babel-config', false)
return
}
const babelConfig = file ? config : defaultBabelOptions
cache.set('babel-config', babelConfig)
return babelConfig
cache.set('babel-config', config)
return config
}
}

0 comments on commit cd39ea7

Please sign in to comment.