Skip to content

Commit cd39ea7

Browse files
yyx990803eddyerburgh
authored andcommitted
fix: babel 7 compat (#43)
1 parent ec223e6 commit cd39ea7

File tree

6 files changed

+155
-157
lines changed

6 files changed

+155
-157
lines changed

lib/compilers/babel-compiler.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@ const babel = require('babel-core')
22
const loadBabelConfig = require('../load-babel-config.js')
33

44
module.exports = function compileBabel (scriptContent, inputSourceMap) {
5+
const babelConfig = loadBabelConfig()
6+
7+
if (!babelConfig) {
8+
return {
9+
code: scriptContent,
10+
sourceMap: inputSourceMap
11+
}
12+
}
13+
514
const sourceMapOptions = {
615
sourceMaps: true,
716
inputSourceMap: inputSourceMap
817
}
918

10-
const babelOptions = Object.assign(sourceMapOptions, loadBabelConfig())
19+
const babelOptions = Object.assign(sourceMapOptions, babelConfig)
1120

1221
const res = babel.transform(scriptContent, babelOptions)
1322

lib/load-babel-config.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ const findBabelConfig = require('find-babel-config')
22
const logger = require('./logger')
33
const cache = require('./cache')
44

5-
var defaultBabelOptions = {
6-
presets: [require.resolve('babel-preset-vue-app')]
7-
}
8-
95
module.exports = function getBabelConfig () {
106
const cachedConfig = cache.get('babel-config')
117
if (cachedConfig) {
128
return cachedConfig
9+
} else if (cachedConfig === false) {
10+
return
1311
} else {
1412
const { file, config } = findBabelConfig.sync(process.cwd(), 0)
1513
if (!file) {
16-
logger.info('no .babelrc found, defaulting to default babel options')
14+
logger.info('no .babelrc found, skipping babel compilation')
15+
cache.set('babel-config', false)
16+
return
1717
}
18-
const babelConfig = file ? config : defaultBabelOptions
19-
cache.set('babel-config', babelConfig)
20-
return babelConfig
18+
cache.set('babel-config', config)
19+
return config
2120
}
2221
}

0 commit comments

Comments
 (0)