Skip to content

Fix Babel 7 compat #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/compilers/babel-compiler.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
}
}
Loading